Mysql master-slave synchronization reset

background

The server was forced to restart, resulting in data inconsistency between the master and slave databases of MySQL. The data difference between the master and slave databases was large, and the data synchronization could not be completed, and an error was reported. Therefore, a master-slave synchronous reset operation is required.

1. First operate the slave library

  • 1) Enter the MySQL command line management interface
mysql -uroot -p
  • 2) stop slave
stop slave;
  • 3) Reset the slave library
reset slave all;
  • 4) Clear the synchronized database
drop database `***`;

2. Operate the main library

  • 1) Reset the synchronization settings of the main library
RESET MASTER;
  • 2) Lock the main library, only read
FLUSH TABLES WITH READ LOCK;
  • 3) Export mysql data
mysqldump –h(ip***) –P(port***) –u(user***) –p(pwd***) --all-databases > /master-dump.sql

4) Unlock the main library

UNLOCK TABLES;

3. Import the data exported from the main library from the library

  • 1) Import data
mysql -r root -p 数据库名 < d:\user\userxxx.sql 
  • 2) Modify the synchronization settings from the library
change master to master_host='主库ip(192.168.1.1)',master_user='root',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=154;
# master_log_file 如下图获取
# master_log_pos 如下图获取
  • 3) Obtain master_log_file and master_log_pos data
    Enter the main database MySQL management interface, execute a command to view master_log_file and master_log_pos data
show master status;

insert image description here

  • 4) Turn on the slave library
start slave;
  • 5) View slave status
show slave status\G;

As shown in the figure below, the configuration is successful.
insert image description here

appendix

  1. Set the master-slave configuration:
    insert image description here
  2. Add data synchronization account:
grant replication slave on *.* to 'root'@'%' identified by '123456';
  1. restart mysql
mysql restart

Guess you like

Origin blog.csdn.net/qq_42102911/article/details/130316815