1.主库和备库都创建同步账号
grant replication slave,replication client on *.* to repl@'192.168.1.%' identified by 'password';
2.主库my.cnf配置
log_bin = mysql-bin
server_id = 10
配置后重启数据库,用show master status;查看状态。如果为empty,可重启服务器后再查看(实际中遇到需要重启服务器)
3.从库my.cnf配置
log_bin = mysql-bin
server_id = 2
relay_log = /var/lib/mysql/mysql-relay-bin
log_slave_updates = 1
read_only = 1
只有server_id是必须配置的。
4.启动复制
change master to master_host = 'ip', master_user = 'repl', master_password = 'password', master_log_file = 'mysql-bin.000001', master_log_pos = 0;
show slave statusG 用来检查复制是否正确执行。
start slave;开始复制
以上步骤。