1、重建前备份从库:
mysqldump -uroot -p --single-transaction --events --triggers --routines --all-databases --socket=/data/my3306/var/mysql.sock> $HOME/my_backup_slave20231026.sql
2、主库导出:
mysqldump -uroot -p --default-character-set=UTF8 --single-transaction --master-data --all-databases --socket=/data/my3306/var/mysql.sock > $HOME/my_backup_master20231026.sql
3、从库导入:
reset master;
mysql -uroot -p --socket=/data/my3306/var/mysql.sock < $HOME/my_backup_master20231026.sql
flush privileges;
4、从库测试到主库连通性
set password for 'dbreplicate'@'%'=password('dbreplicate#1026');
mysql -udbreplicate -p -h$MASTER_IP --protocol=TCP --port=3306
5、从库配置同步进程
stop slave;
change master to
master_host='$MASTER_IP',
master_user='dbreplicate',
master_password='$xxx',
master_port=3306,
master_auto_position=1
;
start slave;
6、主库测试到从库连通性
set password for 'dbreplicate'@'%'=password('dbreplicate#1026');
mysql -udbreplicate -p -h$MASTER_IP --protocol=TCP --port=3306
7、主库配置同步进程
show master status\G
stop slave;
change master to
master_host='$SLAVE_IP',
master_user='dbreplicate',
master_password='$xxx',
master_port=3306,
master_auto_position=1;
start slave;