主库
[mysqld]
server_id = 1
binlog-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.000002
Position: 4707
Binlog_Do_DB: test
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
重启mysql
在从库中配置
[mysqld]
server_id = 2 #服务器id,必须唯一
replicate-rewrite-db=callcenter->dkht_official
replicate-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 event
Master_Host: 192.168.1.151
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 4707
Relay_Log_File: localhost-relay-bin.000004
Relay_Log_Pos: 1503
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB:
Replicate_Do_Table:
1 row in set (0.00 sec)
# 状态中,`Slave_IO_Running: Yes` 和 `Slave_SQL_Running: Yes` 同时保证为 yes 即可判断成功。