How to solve the data gap between the master and slave servers of the MySQL database

Source: Internet
Author: User

Why?MySQL databaseOfMaster/Slave serversIs there a gap between data? The reason is that the master server is busy and the hardware difference between the master server and the slave server is large, which may lead to a large data gap between the master server and the slave server. In order not to affect the application of the MySQL database, we often perform regular data synchronization on the master and slave servers manually. The following describes the steps for manual data synchronization. This process is executed when the load ratio of the database is low. In this case, the master server cannot be updated.

1. Run the following command on the master server:

 
 
  1. Mysql> flush tables with read lock; Use the read lock to lock existing tables to prevent updates to it.
  2.  
  3. Mysql> show master status \ G
  4.  
  5. * *************************** 1. row ***************************
  6.  
  7. File: binlog.000022
  8.  
  9. Position: 592429
  10.  
  11. Binlog_Do_DB:
  12.  
  13. Binlog_Ignore_DB:

Record the value after the FILE and the value after Postion, that is, the log name and its offset.

2. Execute the following statement on the slave server:

 
 
  1. mysql> select MASTER_POS_WAIT('binlog.000022','592429')\G  
  2.  
  3. *************************** 1. row ***************************  
  4.  
  5. MASTER_POS_WAIT('binlog.000022','592429'): 0 

The first parameter of MASTER_POS_WAIT is the File value of the master above, and the second parameter is the Position value of the master above.

If the returned value is 0, the synchronization is successful. If the returned value is-1, the synchronization is timed out and exited.

3. operations on the master server:

 
 
  1. mysql> unlock tables; 

After the preceding steps are completed, the gap between the master and slave servers of the MySQL database can be solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.