Database data synchronization strategy one

One, the scene

       Recently, I encountered a problem of synchronizing data with MySQL. It was necessary to synchronize more than 600,000 data in the test environment to the production environment, and the production data was required to be unaffected. When there is data in the production environment, it is necessary to keep the production data or to integrate the data in the test environment and the production data into a single piece of data during synchronization. Two tables are involved: one table has one field to determine the only piece of data, and the other table requires two fields to determine the only piece of data.

Two, the solution

   Strategy:

      1. Tell the DBA about the involved tables and the characteristics of the table data, and hand them over to the DBA for processing.

      2. Based on temporary table operations, combined with code processing.

  Ideas:

    The first strategy, from my thinking, can write a stored procedure for synchronization, but the DBA said that it involves business data operations and does not participate in data synchronization.

    The second strategy:

         1) Create two temporary tables A and B in the test environment, and synchronize more than 600,000 data to temporary tables A and B;

          2) In the production environment, based on the table structure of the test environment, create two temporary tables C and D;

          3) Synchronize the temporary tables C and D of the production environment from the temporary tables A and B of the test environment;

          4) In the production environment, through the domain name or IP execution interface (involving insert and update operations), the data of the temporary tables C and D are synchronized to the official tables in the production environment.

          5), about half an hour, more than 600,000 synchronization, synchronization is completed.

    tool:

      Navicat: Open Navicat, click Tools , select data synchronization , and perform data synchronization operations for temporary tables.

     Postman: Participate in interface operations

 

Note: This article only explains one way of thinking about synchronizing data. If you have a better strategy, welcome to give pointers, thank you

Guess you like

Origin blog.csdn.net/baidu_28068985/article/details/108279721