Master-slave synchronization of MySQL database

I. Overview:

MYSQL master-slave synchronization architecture is one of the most currently used database architecture, master-slave synchronization so that data can be copied from one database server to another server, the data is copied, a server acts as the master server (master), the remaining servers act as from server (slave).

Second, the topology described:

MySQL001.png

Shown, 192.168.4.10 (host name "10.mysql") as a main map as MySQL database, 192.168.4.20 (host name "20.mysql") as the MySQL database, the data from the primary database is responsible for synchronizing.

Third, the master-slave synchronization configuration instructions:

1, Master configuration

  (1) Authorization database:

      mysql> grant replication slave on *.* to slaveuser@"192.168.4.12" identified by "123456";

  (2) enable binlog log:

      [the root @ 10 ~] # Vim /etc/my.conf
      [mysqld]
      the server_id = 10 # specified primary MySQL database ID
      log-bin # = master10 enable binglog log, the log file is saved in the main MySQL installation directory (/ var / under lib / mysql), the format of the file name is "master22.000001" (maximum capacity per file 500M, the next log file is automatically generated after more than 500M or restart the MySQL service)

    (3) View master status:

       mysql>show master status;

            +-----------------+----------+--------------+------------------+-------------------+
            | File            | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
            +-----------------+----------+--------------+------------------+-------------------+
            | master10.000001 |      154 |              |                  |                   |
            +-----------------+----------+--------------+------------------+-------------------+
            1 row in set (0.00 sec)
2、Slave配置:

    (1) Configuration server_id:

        [@ 20 is the root ~] # Vim /etc/my.conf
        [mysqld]
        the server_id = # 20 is designated ID from a MySQL database

    (2) the configuration information of the primary database (using the login user's root)
       MySQL> Change Master to MASTER_HOST = "192.168.4.10",             
             MASTER_USER = "slaveuser",
             master_password = "123456",
             matser_log_file = "master10.000001",
             MASTER_LOG_POS = 154;
    (3) open slave status
             MySQL> Start slave;
     (. 4) check the status of slave
             mysql> show slave status \ G;

        Following execution of the command is shown below for the two master-slave synchronization configuration normal
               Slave_IO_Running: Yes
               Slave_SQL_Running: Yes

3. Verification:

    Add or delete data operations (192.168.4.10) above the main database, at (192.168.4.20) in time you can see from the above database.

Third, the principle explanation:

     (1) read from the primary database binlog log database IO thread written to, read from the relay database log file from the SQL database thread from the relay log native SQL command is executed in the unit, complete data synchronization;
     (2) If a master-slave configuration database inconsistency before the data, SQL thread will error; If you create an authorized user error in the master database, making it impossible to connect the main database from the database, IO thread will error;
     (3) when the when the database SQL thread executes relay logs inside SQL command failed, SQL thread will shoot down immediately.

      Note that prior to the master-slave configuration MySQL database, the data can not ensure more than the primary database from the database.

Guess you like

Origin www.cnblogs.com/HKROnline-SyncNavigator/p/10971475.html