mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000003 | 437 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
2.3 配置同步信息:masterA上:
mysql> change master to master_host='192.168.10.12',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=437; mysql> start slave; mysql> show slave status\G;
显示有如下状态则正常:
Slave_IO_Running: Yes Slave_SQL_Running: Yes
masterB上:
#本人是测试环境,可以保证没数据写入,否则需要的步骤是:先masterA锁表-->masterA备份数据-->masterA解锁表 -->masterB导入数据-->masterB设置主从-->查看主从
mysql> change master to master_host='192.168.10.11',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=120; start slave; mysql> show slave status\G;
显示有如下状态则正常:
Slave_IO_Running: Yes Slave_SQL_Running: Yes
3.测试主从同步 3.1 在masterA上创建一个数据库测试同步效果mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> create database test01; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | test01 | +--------------------+ 5 rows in set (0.00 sec) mysql> quit Bye [root@masterA data]#
3.2 到masterB查看是否已经同步创建数据库mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | test01 | +--------------------+ 5 rows in set (0.00 sec) mysql> quit Bye [root@masterB data]#
4. 开启MySQL5.6的GTID功能,实现多线程主从复制masterA和masterB分别执行如下命令: