环境:

Master server: 10.224.194.239

Slave    server: 10.224.194.237

步骤:

1.分别在Master/Slaver mysql db 创建backup user:

 
  
  1. GRANT FILE ON *.* TO backup@10.224.194.239 IDENTIFIED BY 'pass'; 
  2. GRANT REPLICATION SLAVE ON *.* TO backup@10.224.194.239 IDENTIFIED BY 'pass'; 
  3.  
  4. GRANT FILE ON *.* TO backup@10.224.194.237 IDENTIFIED BY 'pass'; 
  5. GRANT REPLICATION SLAVE ON *.* TO backup@10.224.194.237 IDENTIFIED BY 'pass'; 

2.在Master server配置/etc/my.cf 文件:

 
  
  1. server-id1 
  2. binlog-do-db=test 
  3. binlog-ignore-db = mysql 
  4.  
  5. replicate-do-db=test 
  6. replicate-ignore-db = mysql 
  7.  
  8. master-host=10.224.194.237 
  9. master-user=backup 
  10. master-password=pass 
  11. master-port=3306 
  12. master-connect-retry=60 
  13.  
  14. slave-skip-errors=all 

3.在Master server配置/etc/my.cf 文件:

 
  
  1. server-id2 
  2.  
  3. binlog-do-db=test 
  4. binlog-ignore-db = mysql 
  5.  
  6. replicate-do-db=test 
  7. replicate-ignore-db = mysql 
  8.  
  9. master-host=10.224.194.239 
  10. master-user=backup 
  11. master-password=pass 
  12. master-port=3306 
  13. master-connect-retry=60 
  14.  
  15. slave-skip-errors=all 

4.重启mysql数据库,验证命令如下:

查看Master状态

 
  
  1. show master status; 
  2. mysql> show master status;
    +-----------------+----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +-----------------+----------+--------------+------------------+
    | mysqllog.000003 | 301 | test | mysql |
    +-----------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

查看Slave状态

 
  
  1. show slave status \G; 
  2. mysql> show slave status \G;
    *************************** 1. row ***************************
    Slave_IO_State: Reconnecting after a failed master event read
    Master_Host: 10.224.194.239
    Master_User: backup
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysqllog.000003
    Read_Master_Log_Pos: 301
    Relay_Log_File: mysqlgsb-relay-bin.000082
    Relay_Log_Pos: 348
    Relay_Master_Log_File: mysqllog.000003
    Slave_IO_Running: No
    Slave_SQL_Running: Yes
    Replicate_Do_DB: test
    Replicate_Ignore_DB: mysql
    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: 301
    Relay_Log_Space: 650
    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: NULL
    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)

    ERROR:
    No query specified

查看同步进程:

 
  
  1. mysql> show processlist \G; 
  2. *************************** 1. row *************************** 
  3.      Id: 1 
  4.    User: system user 
  5.    Host:  
  6.      db: NULL 
  7. Command: Connect 
  8.    Time: 4186 
  9.   State: Waiting for master to send event 
  10.    Info: NULL 
  11. *************************** 2. row *************************** 
  12.      Id: 2 
  13.    User: system user 
  14.    Host:  
  15.      db: NULL 
  16. Command: Connect 
  17.    Time: 3745 
  18.   State: Has read all relay log; waiting for the slave I/O thread to update it 
  19.    Info: NULL 
  20. *************************** 3. row *************************** 
  21.      Id: 5 
  22.    User: root 
  23.    Host: mysqlpri.webex.com:28293 
  24.      db: NULL 
  25. Command: Query 
  26.    Time: 0 
  27.   State: NULL 
  28.    Info: show processlist 
  29. *************************** 4. row *************************** 
  30.      Id: 6 
  31.    User: backup 
  32.    Host: 10.224.194.237:41729 
  33.      db: NULL 
  34. Command: Binlog Dump 
  35.    Time: 135 
  36.   State: Has sent all binlog to slave; waiting for binlog to be updated 
  37.    Info: NULL 
  38. 4 rows in set (0.00 sec) 
  39.  
  40. ERROR:  
  41. No query specified