[MysqLd]
server-id = 1
log_bin = /var/log/MysqL/MysqL-bin.log
expire_logs_days = 10
max_binlog_size = 100M
[MysqLd]
server-id = 2
log_bin = /var/log/MysqL/MysqL-bin.log
expire_logs_days = 10
max_binlog_size = 100M
replicate-do-db=jitui_ad
replicate-do-db=percona
slave-skip-errors = 1062
启动SLAVE
# 查看主服务器当前二进制日志名和偏移量,这个操作的目的是为了在从数据库启动后,从这个点开始进行数据的恢复
SHOW MASTER STATUS;
# 从数据库添加主从
CHANGE MASTER TO MASTER_HOST='192.168.3.91',MASTER_USER='repl',MASTER_PASSWORD='slavepass',MASTER_LOG_FILE='MysqL-bin.000008',MASTER_LOG_POS=8043;
# 启动主从
START SLAVE;
# 停止主从
STOP STLAVE;
# 查看主从状态
SHOW SLAVE STATUS\G;
# 查看slave的状态,如果下面两项值为YES,则表示配置正确:
Slave_IO_Running: Yes
Slave_sql_Running: Yes
INSERT INTO MysqL.user(Host,User,Password) VALUES("localhost","repl",password("slavepass"));
GRANT SELECT,PROCESS,SUPER,REPLICATION SLAVE ON *.* TO 'repl'@localhost IDENTIFIED BY 'slavepass';
GRANT SELECT,REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'slavepass';
FLUSH PRIVILEGES;
CREATE DATABASE percona CHARACTER SET utf8;
GRANT ALL ON percona.* TO 'repl'@localhost IDENTIFIED BY 'slavepass';
GRANT ALL ON percona.* TO 'repl'@'%' IDENTIFIED BY 'slavepass';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON jitui_ad.* TO repl@localhost IDENTIFIED BY 'slavepass';
GRANT ALL PRIVILEGES ON jitui_ad.* TO repl@'%' IDENTIFIED BY 'slavepass';
FLUSH PRIVILEGES;
pt-table-checksum检查表是否一致
pt-table-checksum --nocheck-replication-filters --databases=jitui_ad --replicate=percona.checksums --create-replicate-table --host=127.0.0.1 --port 3306 -urepl -pslavepass
重启从库做主从
pt-slave-restart --user=repl --password=slavepass --host=127.0.0.1 --skip-count=1
pt-slave-restart --user=repl --password=slavepass --host=127.0.0.1 --error-numbers=1062
pt-table-sync保存数据一致
数据,使用--print将结果输出
pt-table-sync --print --sync-to-master --user=repl --password=slavepass h=192.168.3.92 --database jitui_ad
pt-table-sync --execute --replicate percona.checksums --user=repl --password=slavepass --sync-to-master h=192.168.3.92
MysqL> STOP SLAVE;
MysqL> STOP SLAVE IO_THREAD;
MysqL> STOP SLAVE sql_THREAD;
MysqL> RESET SLAVE ALL;
cd /var/lib/MysqL
service MysqL stop
rm -f master.info relay-*`
service MysqL start
参考