mysql主从不同步怎么办
mysql主从不同步解决方法:
1、进入主库,进行锁表
使用命令:
mysql> flush tables with read lock;
注意:该处是锁定为只读状态,语句不区分大小写
2、进行数据备份
#把数据备份到mysql.bak.sql文件 [root@server01 mysql]#mysqldump -uroot -p -hlocalhost > mysql.bak.sql
3、查看master 状态
mysql> show master status; +-------------------+----------+--------------+-------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+-------------------------------+ | mysqld-bin.000001 | 3260 | | mysql,test,information_schema | +-------------------+----------+--------------+-------------------------------+ 1 row in set (0.00 sec)
4、把mysql备份文件传到从库机器,进行数据恢复
#使用scp命令 [root@server01 mysql]# scp mysql.bak.sql root@192.168.128.101:/tmp/
5、停止从库的状态
mysql> stop slave;
6、然后到从库执行mysql命令,导入数据备份
mysql> source /tmp/mysql.bak.sql
7、设置从库同步
change master to master_host = '192.168.128.100', master_user = 'rsync', master_port=3306, master_password='', master_log_file = 'mysqld-bin.000001', master_log_pos=3260;
8、重新开启从同步
mysql> start slave;
查看同步状态
mysql> show slave statusG
查看:
Slave_IO_Running: Yes Slave_SQL_Running: Yes
更多Python知识,请关注:云海天python教程网!!
来源:PY学习网:原文地址:https://www.py.cn/article.html