主库
[mysqld]server_id = 1binlog-do-db = test #需要同的数据库log_bin = mysql-bin # 开启log_bin
然后需要创建从库同步时所需要的账户
grant replication slave on *.* to 'repl'@'192.168.1.%' identified by 'repl..2017';
查看master状态
mysql> show master status \G;*************************** 1. row ***************************File: mysql-bin.000002Position: 4707Binlog_Do_DB: testBinlog_Ignore_DB:Executed_Gtid_Set:1 row in set (0.00 sec)
重启mysql
在从库中配置
[mysqld]server_id = 2 #服务器id,必须唯一replicate-rewrite-db=callcenter->dkht_officialreplicate-do-table=dkht_official.plt_service_list1000 # 需要同步的数据库expire_logs_days=10//linux下出现table名大小写异常的问题,设置大小写不敏感lower_case_table_names=1
重启mysql
连接主库
mysql > change master to master_host='192.168.1.151',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000002',master_log_pos=3703;
mysql > start slave;
查看同步状态
mysql> show slave status \G;*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.1.151Master_User: replMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000002Read_Master_Log_Pos: 4707Relay_Log_File: localhost-relay-bin.000004Relay_Log_Pos: 1503Relay_Master_Log_File: mysql-bin.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: testReplicate_Ignore_DB:Replicate_Do_Table:1 row in set (0.00 sec)# 状态中,`Slave_IO_Running: Yes` 和 `Slave_SQL_Running: Yes` 同时保证为 yes 即可判断成功。