Mysql primary synchronization (CentOS articles) from the database

surroundings:

Master: centos 5.2 mysql 5.1.35 Source IP: 192.168.1.22 from the server: centos 5.2 mysql 5.1.35 Source IP: 192.168.1.33

Configuration:

First, the primary server 1.1, create a replication user with permission replication slave. mysql> grant replication slave on * * to 'repl'@'192.168.1.22' identified by 'repl';. 1.2, edit my.cnf file vi /etc/my.cnf 
added 
server-id = 1 
and turn on log-bin binary log files 
log-bin = mysql-bin Note: the need to default to remove the server-id = 1 1.3, starting mysql database mysqld_safe --user = mysql & 1.4, setting a read lock mysql> flush tables with read lock; 1.5, to give binlog log file names and offsets mysql> show master status; + ------------------ + ---------- + ------ + ------------------ + --------
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ------------ + ------ + -------------- + ----------------- ---------- - +
| MySQL-bin.0000010 | 106 | | | 
+ ------------------ + ---------- + -------------- + ---- -------------- + 1.6, mysqldump test database backup to synchronize> test.sql 1.7, unlock mysql> unlock tables; Second, from the server 2.1, edit my.cnf file vi / etc /my.cnf 
added 
server-id = 2 Note: the need to default to remove the server-id = 1 2.2, starting from the database mysqld_safe --user = mysql & 2.3, corresponding to the set from the database mysql> Change to Master 
        -> MASTER_HOST = '192.168.1.22' 
        -> MASTER_USER = 'the repl' 
        -> master_password = 'the repl' 
        -> MASTER_LOG_FILE = 'MySQL-bin.0000010' 
        -> MASTER_LOG_POS = 106; 2.4, starting from the slave server thread mysql> start slave; performed show processlist command displays the following process: MySQL> show processlist \ G 
*************************** 2. Row ******* ******************** 
         Id: 2 
     the User: system user 
     Host:    
         db: NULL 
the Command: Connect 
     Time: 2579 
    State: Has the Read All Relay log; Waiting for at The slave the I / O the Thread to Update IT 
     Info: NULL represents the slave has been connected to the master, began to accept and execute the logs 2.5, see the slave thread state mysql > show slave status; *************************** 1. row *************** ************
               Slave_IO_State: Waiting for Master to Send Event
                  MASTER_HOST: 192.168.1.22 MASTER_USER: the repl
                  MASTER_PORT: 3306
                Connect_Retry: 60
              Master_Log_File: MySQL-bin.0000010
          Read_Master_Log_Pos: 106
               Relay_Log_File: CentOS-relay- bin.000002
                RELAY_LOG_POS: 529
        Relay_Master_Log_File: mysql-bin.0000010
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:           Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 830
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec) 

Verify that the configuration is correct

Performing show slave status \ G from the server; 
Waiting for Master to Send Event 
Slave_IO_Running: Yes 
Slave_SQL_Running: Yes same time as two or more rows arranged to illustrate successful Yes
 

test

1, to create the user table mysql test database at the master server> use Test; 
MySQL> Create Table user (ID int); 2, viewing user table mysql> use test from the server; 
MySQL> Show Tables like 'user'; 
+ + ---------------------- 
| Tables_in_test (the User) | 
+ -------------------- - + 
| the User |    
+ ---------------------- + 
1 Row in the SET (0.00 sec) master-slave data synchronization success. 

problem?

1. When The slave I / O thread stops because master and slave have equal MySQL server ids while viewing a slave state from the database; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it) instructions from the server-id server side in the same my.cnf. Solution: Modify the my.cnf in the server-id, and restart the database service. my.cnf file default have server-id = 1 otherwise specified database name of the primary server my.cnf # binlog-do-db = backup needs, you can write multiple lines
# binlog-ignore-db = backup of the database name does not need to be write multiple lines
from the server my.cnf # replicate-do-db = database name test need to back up
# replicate-ignore-db = mysql database overlooked
# master-connect-retry = 60 from the server if the primary server was found broken, again connected to the time difference (s) may also be provided directly modify the configuration file my.cnf = MySQL-bin-log bin
Master-Host-User 192.168.1.22master = = = the repl password replmaster-
Master-Port = 3306

From the master synchronization server maintains various reasons, resulting in inconsistent data from the master, at the time of low load, manual synchronization executing mysql> flush tables with read lock on the primary server;. Query OK, rows affected ( 0.01 sec) mysql> show master status; + ------------------ + ---------- + -------------- + + ------------------
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ------------------ + - + ------------------ + -------------- + --------
| MySQL-bin.0000011 | 260 | | | 
+ ------------------ + ---------- + -------------- + ------------------ + offset in the file name and the current binary performed to obtain a master server from the server, execute the command from the server to synchronize with the primary server mysql> select master_pos_wait ( 'MySQL-bin.0000011', '260.'); 
+ ----------------------------------- + --------------- 
| MASTER_POS_WAIT ( 'MySQL-bin.0000011', '260.' )            | 
+--------------------------------------------------+ 
| 0 |   
+ ---------------------------------------------- + ---- 
. 1 in Row SET (0.01 sec) when synchronization is complete, the unlocking performed on the master server mysql> unlock tables; master switch when the primary server fails from the server, from the server if the primary server may use the following steps: 1, to ensure that all updates have been performed all relay log in from a database, execute from the server stop slave io_thread, inspection show processlist, to see if the state is has read all relay log, indicates that the update is completed .mysql> stop slave io_thread ; 
Query the OK, 0 affected (0.00 sec) 
MySQL> Show PROCESSLIST \ G; Row 2. *** *************************** ************************
     Id: 2
   the User: User System
   the Host: 
     DB: NULL
the Command: Connect
   Time: 4757
  State: Has Read All Relay log; waiting for the slave I / O thread to update it
   Info: NULL2, performed on the slave stop slave, reset master command, reset to the primary database MySQL> STOP Slave; 
Query the OK, 0 affected (0.00 sec) 
MySQL> Master RESET; 
Query the OK, 0 affected (0.00 sec)

3, delete the new master database directory master.info and relay-log.info file, otherwise next time will restart according to start from the server


Author: Mu UI4062818
link: https: //www.imooc.com/article/41306
Source: Mu class network

Guess you like

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