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 status\G 用來檢查複製是否正確執行。
start slave;開始複製
以上步驟。