场景:由M--〉S1变为M-->S1&M-->S2
传统复制:
环境:
M:10.1.12.122 ,3306
S1:10.1.12.123,3306
拟添加的S2:10.1.12.122,3307
1) 从S1:10.1.12.123,3306 导出数据:
[[email protected] ~]$ mysqldump -uroot -p --single-transaction --dump-slave=2 -A >123slave.sql
Enter password:
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don‘t want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
注意:使用 --dump-slave参数,而不是master-data=2参数
2)构建chang master 语句
more 123slave.sql
#CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000011‘, MASTER_LOG_POS=1793;
在M上执行show master status
+------------------+----------+--------------+------------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------------------------------+
| mysql-bin.000011 | 1793 | | | d26e7493-ce3a-11e6-90ff-005056a42880:1-27 |
+------------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec)
使用的主库的binlog位置
CHANGE MASTER TO
MASTER_HOST=‘10.1.12.122‘,
MASTER_PORT=3306,
MASTER_USER=‘rep1‘,
MASTER_PASSWORD=‘pass1234‘,
MASTER_LOG_FILE=‘mysql-bin.000011‘,
MASTER_LOG_POS=1793;
3)导入数据,执行change mater语句
[[email protected] ~]$ mysql -h127.0.0.1 -uroot -ppass1234 -P3307<123slave.sql
mysql> CHANGE MASTER TO
-> MASTER_HOST=‘10.1.12.122‘,
-> MASTER_PORT=3306,
-> MASTER_USER=‘rep1‘,
-> MASTER_PASSWORD=‘pass1234‘,
-> MASTER_LOG_FILE=‘mysql-bin.000011‘,
-> MASTER_LOG_POS=1793;
ERROR 1776 (HY000): Parameters MASTER_LOG_FILE, MASTER_LOG_POS, RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION is active.
解决:mysqladmin -uroot -ppass1234 -h127.0.0.1 -P3307 shutdown
重启数据库后,执行成功;
使用GTID方式:
1)清理环境
在10.1.12.122,3307, drop database,reset slave&master
2)重新导出和导入数据:
CHANGE MASTER TO
MASTER_HOST=‘10.1.12.122‘,
MASTER_PORT=3306,
MASTER_USER=‘rep1‘,
MASTER_PASSWORD=‘pass1234‘,
MASTER_AUTO_POSITION=1;
由M--〉S1变为M-->S1&M-->S2