1.先进入主库,进行锁表,防止数据写入
mysql> flush tables with read lock;
2.进行数据备份
/usr/local/mysql/bin/mysqldump -uroot -p test> test.sql
3.查看master 状态
mysql> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| mysql-bin.000010 | 179567203 | | | |
+------------------+-----------+--------------+------------------+-------------------+
4.停止从库
mysql> stop slave;
5.从库还原数据
mysql> source test.sql;
6.从新设置主从同步
CHANGE MASTER TO MASTER_HOST='172.16.2.216',MASTER_USER='repl',MASTER_PASSWORD='123456',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000010', MASTER_LOG_POS=179567203;
7.从新开启主从同步
mysql> start slave;
8.查看主从同步状态
mysql> show slave status\G
9.主库解除锁
mysql> UNLOCK TABLES;