MySql教程

mysql 重新主从复制

本文主要是介绍mysql 重新主从复制,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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;

 

这篇关于mysql 重新主从复制的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!