Created
June 17, 2015 11:10
-
-
Save rodesousa/f719aa70fb786c4ce624 to your computer and use it in GitHub Desktop.
Replication MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# PARAM | |
mysql_master=<%= @DBMY_MASTER_HOST %> | |
user_mysql=root | |
password_user_mysql=<%= @USER_ROOT_DBMY_SLAVE_PASSWORD %> | |
replication_user=<%= @REP_USER %> | |
replication_password=<%= @REP_PASSWORD %> | |
read -p "Etes vous sur de vouloir installer la replication ? [Y/N]" -n 1 -r | |
if [[ ! $REPLY =~ ^[YyOo]$ ]] | |
then | |
echo 'Abandon' | |
exit 1 | |
fi | |
master_status=$(mysql -h$mysql_master -u $replication_user -p$replication_password -e " SHOW MASTER STATUS; " | awk '(NR==2 || NR==3) {print $0}') | |
master_file=$(echo $master_status | cut --delimiter=' ' -f 1) | |
master_pos=$(echo $master_status | cut --delimiter=' ' -f 2) | |
mysql -u $user_mysql -p$password_user_mysql -e"STOP SLAVE;" | |
mysql -u $user_mysql -p$password_user_mysql -e"CHANGE MASTER TO MASTER_HOST='$mysql_master', MASTER_USER='$replication_user', MASTER_PASSWORD='$replication_password', MASTER_LOG_FILE='$master_file', MASTER_LOG_POS=$master_pos" | |
mysql -u $user_mysql -p$password_user_mysql -e"START SLAVE;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment