1. 程式人生 > >MySQL GTID空庫複製搭建

MySQL GTID空庫複製搭建

MySQL GTID空庫複製搭建
環境
1. 主備庫開啟gtid
2. 備庫上停掉之前的傳統複製並清空資訊
3. 指定主庫
4. 備庫重新連線

MySQL GTID空庫複製搭建

環境

  • 主庫:IP:192.168.1.21;版本:5.7.18
  • 備庫:IP:192.168.1.128;版本:5.6.36

1. 主備庫開啟gtid


 
  1. #vim my.cnf
  2. gtid_mode=on
  3. enforce_gtid_consistency=on
  4. #log-slave-updates=ON(5.7不需要新增,會將gtid資訊放在mysql.gtid_executed表中)

2. 備庫上停掉之前的傳統複製並清空資訊


 
  1. [email protected] : (none) 11:56:00> stop slave;
  2. Query OK, 0 rows affected (0.02 sec)
  3. [email protected] : (none) 11:56:33> reset slave all;
  4. Query OK, 0 rows affected (0.08 sec)

3. 指定主庫


 
  1. #複製賬號沿用先前的賬號repl和密碼repl
  2. [email protected] : (none
    ) 01:43:29> change master to master_host='192.168.1.21',master_user='repl',master_password='repl',master_auto_position=1;
  3. Query OK, 0 rows affected, 2 warnings (0.08 sec)
  4. [email protected] : (none) 01:57:13> show slave status\G;
  5. *************************** 1. row ***************************
  6. Slave_IO_State:
  7. Master_Host: 192.168.1.21
  8. Master_User: repl
  9. Master_Port: 3306
  10. Connect_Retry: 60
  11. Master_Log_File:
  12. Read_Master_Log_Pos: 4
  13. Relay_Log_File: mysql-relay-bin.000001
  14. Relay_Log_Pos: 4
  15. Relay_Master_Log_File:
  16. Slave_IO_Running: No
  17. Slave_SQL_Running: Yes
  18. Replicate_Do_DB: sbtest
  19. Replicate_Ignore_DB:
  20. Replicate_Do_Table:
  21. Replicate_Ignore_Table:
  22. Replicate_Wild_Do_Table:
  23. Replicate_Wild_Ignore_Table:
  24. Last_Errno: 0
  25. Last_Error:
  26. Skip_Counter: 0
  27. Exec_Master_Log_Pos: 0
  28. Relay_Log_Space: 151
  29. Until_Condition: None
  30. Until_Log_File:
  31. Until_Log_Pos: 0
  32. Master_SSL_Allowed: No
  33. Master_SSL_CA_File:
  34. Master_SSL_CA_Path:
  35. Master_SSL_Cert:
  36. Master_SSL_Cipher:
  37. Master_SSL_Key:
  38. Seconds_Behind_Master: 0
  39. Master_SSL_Verify_Server_Cert: No
  40. Last_IO_Errno: 1593
  41. Last_IO_Error: The slave IO thread stops because the master has @@GLOBAL.GTID_MODE OFF and this server has @@GLOBAL.GTID_MODE ON
  42. Last_SQL_Errno: 0
  43. Last_SQL_Error:
  44. Replicate_Ignore_Server_Ids:
  45. Master_Server_Id: 12001
  46. Master_UUID:
  47. Master_Info_File: mysql.slave_master_info
  48. SQL_Delay: 0
  49. SQL_Remaining_Delay: NULL
  50. Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
  51. Master_Retry_Count: 86400
  52. Master_Bind:
  53. Last_IO_Error_Timestamp: 170523 01:57:13
  54. Last_SQL_Error_Timestamp:
  55. Master_SSL_Crl:
  56. Master_SSL_Crlpath:
  57. Retrieved_Gtid_Set:
  58. Executed_Gtid_Set:
  59. Auto_Position: 1
  60. 1 row in set (0.00 sec)
  61. #報錯顯示主庫沒有開啟gtid
  62. #檢視主庫是否開啟gtid:
  63. mysql> show variables like 'GTID_MODE%';
  64. +---------------+-------+
  65. | Variable_name | Value |
  66. +---------------+-------+
  67. | gtid_mode | OFF |
  68. +---------------+-------+
  69. 1 row in set (0.03 sec)
  • 檢視主庫配置檔案發現,主庫的gtid_mode=on以及enforce_gtid_consistency=on放在了[mysqld_safe]下,而沒有放在[mysqld]下

 
  1. #修改vim /usr/local/mysql/my.cnf(需要在mysqld下新增,否則會導致不生效)
  2. [mysqld]
  3. gtid_mode=on
  4. enforce_gtid_consistency=on

 
  1. #重啟主庫mysql
  2. [[email protected]-192-168-1-21 mysql]# service mysql stop
  3. Shutting down MySQL.... SUCCESS!
  4. [[email protected]-192-168-1-21 mysql]# service mysql start
  5. Starting MySQL.. SUCCESS!
  6. mysql> show variables like 'GTID_MODE%';
  7. +---------------+-------+
  8. | Variable_name | Value |
  9. +---------------+-------+
  10. | gtid_mode | ON |
  11. +---------------+-------+
  12. 1 row in set (0.01 sec)

4. 備庫重新連線


 
  1. [email protected] : (none) 02:30:41> stop slave;
  2. Query OK, 0 rows affected (0.01 sec)
  3. [email protected] : (none) 02:30:46> start slave;
  4. Query OK, 0 rows affected (0.02 sec)
  5. 相關推薦

    no