Chapter VIII of the master-slave replication mysql

From the master copy mysql

Set up a master-slave replication

1. Prepare three hosts (this is a multi-instance)

3307 master
3308 salve1
3309 salve2

 

2. master node set

[ Mysqld ] 
log - bin = / Data / 3307 / MySQL - bin        - opening binary 
binlog_format = Row                   - log format 
Skip - name - Resolve                   - Close Domain Name 
Server - ID = 3307          

 

 

3. salve node set

[mysqld]
server-id=
skip-name-resolve

 

 

4. Start multi-instance

 

5. maste create a replication account

 

grant replication slave on *.* to repl@'10.0.0.%' identified by '123456';
flush privileges;

 

 

6. Analysis of the situation master node

1) The new environment, do not need to back up the master data repository   

Directly from the first binlog (mysql-bin.000001) of the head position (120)

 

2) the main library work for some time, call the shots from copy

① Backup main library 

mysqldump -uroot -p123456 -S /data/3307/mysql.sock -A -R  --triggers --master-data=2 --single-transaction >/tmp/full.sql

[root@db2 ~]# sed -n '22p' /tmp/full.sql
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=1036;

 

② to recover from the library

salve node operation

mysql -S /data/3308/mysql.sock 
mysql> set sql_log_bin=0;
mysql> source /tmp/full.sql

 

 

7 to open the main database synchronization from the library

help:

 help change master to

 

 

mysql -S /data/3308/mysql.sock

CHANGE MASTER TO
  MASTER_HOST='10.0.0.87',
  MASTER_USER='repl',
  MASTER_PASSWORD='123456',
  MASTER_PORT=3307,
  MASTER_LOG_FILE='mysql-bin.000004',
  MASTER_LOG_POS=1036;

 

 

From 8 to open the main

Open IO and SQL thread

salve node operation

mysql> start slave;

 

9 View from the main state

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.87
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000004
          Read_Master_Log_Pos: 1448
               Relay_Log_File: 3308-relay-bin.000002
                Relay_Log_Pos: 695
        Relay_Master_Log_File: mysql-bin.000004
             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: 1448
              Relay_Log_Space: 867
              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: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 3307
                  Master_UUID: 8737f473-d9e6-11e9-afbf-000c2967cb96
             Master_Info_File: /data/3308/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.00 sec)

 

Guess you like

Origin www.cnblogs.com/augustyang/p/11543565.html