Mysql has two masters and slaves, which means master server and slave server. The structure has one master and one slave: one Master and one Slave. One master and multiple slaves: one Master and multiple slaves.
Recommended course: MySQL tutorial
##Master-slave synchronization solution
First go to the Master library:mysql>show processlist; 查看下进程是否Sleep太多。发现很正常。 show master status; 也正常。 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)
mysql> show slave status\G Slave_IO_Running: Yes Slave_SQL_Running: No
Here are two solutions:
Method 1: Ignore the error and continue synchronization
This method is suitable for situations where the data in the master-slave database are not very different, or the data does not need to be completely unified, and the data requirements are not Strict situation Solution:stop slave; #表示跳过一步错误,后面的数字可变 set global sql_slave_skip_counter =1; start slave; 之后再用mysql> show slave status\G 查看: Slave_IO_Running: Yes Slave_SQL_Running: Yes ok,现在主从同步状态正常了。。。
Method 2: Re-do master-slave, complete synchronization
mysql> flush tables with read lock;
[root@server01 mysql]#mysqldump -uroot -p -hlocalhost > mysql.bak.sql
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)
[root@server01 mysql]# scp mysql.bak.sql root@192.168.128.101:/tmp/
mysql> stop slave;
mysql> source /tmp/mysql.bak.sql
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;
mysql> stop slave;
mysql> show slave status\G 查看; Slave_IO_Running: Yes Slave_SQL_Running: Yes
The above is the detailed content of What should I do if two mysql masters and slaves are synchronized?. For more information, please follow other related articles on the PHP Chinese website!