《MySQL5.7多源復制Mysql入門》要點:
本文介紹了MySQL5.7多源復制Mysql入門,希望對您有用。如果有疑問,可以聯系我們。
- #GTID?
- gtid-mode?=?on?
- binlog_gtid_simple_recovery=1?
- enforce_gtid_consistency=1?
- binlog_format?=?row?
- skip_slave_start?=?1?
- log-bin?=?/data/mysql/mysql_3307/logs/binlog/mysql-bin?
二、主庫創建復制賬號:
- #binlog?
- binlog_format?=?row?
- server-id?=?1343307?
- log-bin?=?/data/mysql/mysql_3307/logs/binlog/mysql-bin?
- #GTID?
- gtid-mode?=?on?
- binlog_gtid_simple_recovery=1?
- enforce_gtid_consistency=1?
- #修改MySQL存儲master-info和relay-info的方式,即從文件存儲改為表存儲?
- master_info_repository=TABLE?
- relay_log_info_repository=TABLE?
- replicate_ignore_db=mysql #忽略mysql庫的同步?
- skip_slave_start?=?1?
三:從庫啟動復制:
- Master1:grant?replication?slave,replication?client?on?*.*?to?sampson_132@'10.157.26.%'identified?by?'sampson_132';?
- Master2:grant?replication?slave,replication?client?on?*.*?to?sampson_133@'10.157.26.%'identified?by?'sampson_133';?
也可以start slave for channel 'Master_132 '啟動單個channel的復制.
- mysql>?change?master?to?master_host='10.157.26.132',master_port=3307,master_user='sampson_132',master_password='sampson_132',master_auto_position=1?for?channel?'Master_132';?
- mysql>change?master?to?master_host='10.157.26.133',master_port=3307,master_user='sampson_133',master_password='sampson_133',master_auto_position=1?for?channel?'Master_133';?
- mysql>start?slave;?
通過查看performance_schema相關的表查看同步狀態:
- mysql>?show?slave?status\G?
- ***************************?1.?row?***************************?
- ???????????????Slave_IO_State:?Waiting?for?master?to?send?event?
- ??????????????????Master_Host:?10.157.26.132?
- ??????????????????Master_User:?sampson_132?
- ??????????????????Master_Port:?3307?
- ????????????????Connect_Retry:?60?
- ??????????????Master_Log_File:?mysql-bin.000001?
- ??????????Read_Master_Log_Pos:?154?
- ???????????????Relay_Log_File:?relay_log-master_132.000002?
- ????????????????Relay_Log_Pos:?367?
- ????????Relay_Master_Log_File:?mysql-bin.000001?
- ?????????????Slave_IO_Running:?Yes?
- ????????????Slave_SQL_Running:?Yes?
- ??????????????Replicate_Do_DB:?
- ??????????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:?154?
- ??????????????Relay_Log_Space:?579?
- ??????????????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:?1323307?
- ??????????????????Master_UUID:?8785129a-3ace-11e7-9f13-fa163e48cafd?
- ?????????????Master_Info_File:?mysql.slave_master_info?
- ????????????????????SQL_Delay:?0?
- ??????????SQL_Remaining_Delay:?NULL?
- ??????Slave_SQL_Running_State:?Slave?has?read?all?relay?log;?waiting?for?more?updates?
- ???????????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:?1?
- ?????????Replicate_Rewrite_DB:?
- ?????????????????Channel_Name:?master_132?
- ???????????Master_TLS_Version:?
- ***************************?2.?row?***************************?
- ???????????????Slave_IO_State:?Waiting?for?master?to?send?event?
- ??????????????????Master_Host:?10.157.26.133?
- ??????????????????Master_User:?sampson_133?
- ??????????????????Master_Port:?3307?
- ????????????????Connect_Retry:?60?
- ??????????????Master_Log_File:?mysql-bin.000001?
- ??????????Read_Master_Log_Pos:?154?
- ???????????????Relay_Log_File:?relay_log-master_133.000002?
- ????????????????Relay_Log_Pos:?367?
- ????????Relay_Master_Log_File:?mysql-bin.000001?
- ?????????????Slave_IO_Running:?Yes?
- ????????????Slave_SQL_Running:?Yes?
- ??????????????Replicate_Do_DB:?
- ??????????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:?154?
- ??????????????Relay_Log_Space:?579?
- ??????????????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:?1333307?
- ??????????????????Master_UUID:?3d5ae510-3acf-11e7-82a4-fa163e8e91ad?
- ?????????????Master_Info_File:?mysql.slave_master_info?
- ????????????????????SQL_Delay:?0?
- ??????????SQL_Remaining_Delay:?NULL?
- ??????Slave_SQL_Running_State:?Slave?has?read?all?relay?log;?waiting?for?more?updates?
- ???????????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:?1?
- ?????????Replicate_Rewrite_DB:?
- ?????????????????Channel_Name:?master_133?
- ???????????Master_TLS_Version:?
- rows?in?set?(0.01?sec)?
- mysql>?select?*?from?performance_schema.replication_connection_status\G?
- ***************************?1.?row?***************************?
- ?????????????CHANNEL_NAME:?master_132?
- ???????????????GROUP_NAME:?
- ??????????????SOURCE_UUID:?8785129a-3ace-11e7-9f13-fa163e48cafd?
- ????????????????THREAD_ID:?89?
- ????????????SERVICE_STATE:?ON?
- COUNT_RECEIVED_HEARTBEATS:?1?
- ?LAST_HEARTBEAT_TIMESTAMP:?2017-05-17?16:59:45?
- ?RECEIVED_TRANSACTION_SET:?
- ????????LAST_ERROR_NUMBER:?0?
- ???????LAST_ERROR_MESSAGE:?
- ?????LAST_ERROR_TIMESTAMP:?0000-00-00?00:00:00?
- ***************************?2.?row?***************************?
- ?????????????CHANNEL_NAME:?master_133?
- ???????????????GROUP_NAME:?
- ??????????????SOURCE_UUID:?3d5ae510-3acf-11e7-82a4-fa163e8e91ad?
- ????????????????THREAD_ID:?91?
- ????????????SERVICE_STATE:?ON?
- COUNT_RECEIVED_HEARTBEATS:?1?
- ?LAST_HEARTBEAT_TIMESTAMP:?2017-05-17?16:59:45?
- ?RECEIVED_TRANSACTION_SET:?
- ????????LAST_ERROR_NUMBER:?0?
- ???????LAST_ERROR_MESSAGE:?
- ?????LAST_ERROR_TIMESTAMP:?0000-00-00?00:00:00?
- rows?in?set?(0.01?sec)?
- mysql>CREATE?DATABASE?/*!32312?IF?NOT?EXISTS*/?`sampson_132`?/*!40100?DEFAULT?CHARACTER?SET?utf8mb4?*/;?
- mysql>use?sampson_132?
- mysql>?create?table?t_132(id?int?primary?key?auto_increment,name?varchar(20)?not?null);?
- mysql>?insert?into?t_132(id,name)values(1,'132'),(2,'132'),(3,'132');?
- mysql>?select?*?from?t_132;?
- +----+------+?
- |?id?|?name?|?
- +----+------+?
- |??1?|?132??|?
- |??2?|?132??|?
- |??3?|?132??|?
- +----+------+?
- rows?in?set?(0.00?sec)?
MYSQL應用Master2建庫建表并插入數據:
?
- mysql>?CREATE?DATABASE?/*!32312?IF?NOT?EXISTS*/?`sampson_133`?/*!40100?DEFAULT?CHARACTER?SET?utf8mb4?*/;?
- mysql>?use?sampson_133?
- mysql>?create?table?t_133(id?int?primary?key?auto_increment,name?varchar(20)?not?null);?
- mysql>?insert?into?t_133(id,name)values(1,'133'),(2,'133'),(3,'133');?
- mysql>?select?*?from?sampson_133.t_133;?
- +----+------+?
- |?id?|?name?|?
- +----+------+?
- |??1?|?133??|?
- |??2?|?133??|?
- |??3?|?133??|?
- +----+------+?
- rows?in?set?(0.00?sec)?
MYSQL應用Slave查看數據是否同步:
?
- mysql>?show?databases;?
- +--------------------+?
- |?Database???????????|?
- +--------------------+?
- |?information_schema?|?
- |?mysql??????????????|?
- |?performance_schema?|?
- |?sampson_132????????|?
- |?sampson_133????????|?
- |?sys????????????????|?
- +--------------------+?
- rows?in?set?(0.00?sec)?
- ??
- mysql>?select?*?from?sampson_132.t_132;?
- +----+------+?
- |?id?|?name?|?
- +----+------+?
- |??1?|?132??|?
- |??2?|?132??|?
- |??3?|?132??|?
- +----+------+?
- rows?in?set?(0.00?sec)?
- ??
- mysql>?select?*?from?sampson_133.t_133;?
- +----+------+?
- |?id?|?name?|?
- +----+------+?
- |??1?|?133??|?
- |??2?|?133??|?
- |??3?|?133??|?
- +----+------+?
- rows?in?set?(0.00?sec)?
MYSQL應用再次查看從庫狀態:
?
- mysql>?show?slave?status\G?
- ***************************?1.?row?***************************?
- ???????????????Slave_IO_State:?Waiting?for?master?to?send?event?
- ??????????????????Master_Host:?10.157.26.132?
- ??????????????????Master_User:?sampson_132?
- ??????????????????Master_Port:?3307?
- ????????????????Connect_Retry:?60?
- ??????????????Master_Log_File:?mysql-bin.000001?
- ??????????Read_Master_Log_Pos:?930?
- ???????????????Relay_Log_File:?relay_log-master_132.000002?
- ????????????????Relay_Log_Pos:?1143?
- ????????Relay_Master_Log_File:?mysql-bin.000001?
- ?????????????Slave_IO_Running:?Yes?
- ????????????Slave_SQL_Running:?Yes?
- ??????????????Replicate_Do_DB:?
- ??????????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:?930?
- ??????????????Relay_Log_Space:?1355?
- ??????????????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:?1323307?
- ??????????????????Master_UUID:?8785129a-3ace-11e7-9f13-fa163e48cafd?
- ?????????????Master_Info_File:?mysql.slave_master_info?
- ????????????????????SQL_Delay:?0?
- ??????????SQL_Remaining_Delay:?NULL?
- ??????Slave_SQL_Running_State:?Slave?has?read?all?relay?log;?waiting?for?more?updates?
- ???????????Master_Retry_Count:?86400?
- ??????????????????Master_Bind:?
- ??????Last_IO_Error_Timestamp:?
- ?????Last_SQL_Error_Timestamp:?
- ???????????????Master_SSL_Crl:?
- ???????????Master_SSL_Crlpath:?
- ???????????Retrieved_Gtid_Set:?8785129a-3ace-11e7-9f13-fa163e48cafd:1-3?
- ????????????Executed_Gtid_Set:?3d5ae510-3acf-11e7-82a4-fa163e8e91ad:1-3,?
- 8785129a-3ace-11e7-9f13-fa163e48cafd:1-3?
- ????????????????Auto_Position:?1?
- ?????????Replicate_Rewrite_DB:?
- ?????????????????Channel_Name:?master_132?
- ???????????Master_TLS_Version:?
- ***************************?2.?row?***************************?
- ???????????????Slave_IO_State:?Waiting?for?master?to?send?event?
- ??????????????????Master_Host:?10.157.26.133?
- ??????????????????Master_User:?sampson_133?
- ??????????????????Master_Port:?3307?
- ????????????????Connect_Retry:?60?
- ??????????????Master_Log_File:?mysql-bin.000001?
- ??????????Read_Master_Log_Pos:?930?
- ???????????????Relay_Log_File:?relay_log-master_133.000002?
- ????????????????Relay_Log_Pos:?1143?
- ????????Relay_Master_Log_File:?mysql-bin.000001?
- ?????????????Slave_IO_Running:?Yes?
- ????????????Slave_SQL_Running:?Yes?
- ??????????????Replicate_Do_DB:?
- ??????????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:?930?
- ??????????????Relay_Log_Space:?1355?
- ??????????????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:?1333307?
- ??????????????????Master_UUID:?3d5ae510-3acf-11e7-82a4-fa163e8e91ad?
- ?????????????Master_Info_File:?mysql.slave_master_info?
- ????????????????????SQL_Delay:?0?
- ??????????SQL_Remaining_Delay:?NULL?
- ??????Slave_SQL_Running_State:?Slave?has?read?all?relay?log;?waiting?for?more?updates?
- ???????????Master_Retry_Count:?86400?
- ??????????????????Master_Bind:?
- ??????Last_IO_Error_Timestamp:?
- ?????Last_SQL_Error_Timestamp:?
- ???????????????Master_SSL_Crl:?
- ???????????Master_SSL_Crlpath:?
- ???????????Retrieved_Gtid_Set:?3d5ae510-3acf-11e7-82a4-fa163e8e91ad:1-3?
- ????????????Executed_Gtid_Set:?3d5ae510-3acf-11e7-82a4-fa163e8e91ad:1-3,?
- 8785129a-3ace-11e7-9f13-fa163e48cafd:1-3?
- ????????????????Auto_Position:?1?
- ?????????Replicate_Rewrite_DB:?
- ?????????????????Channel_Name:?master_133?
- ???????????Master_TLS_Version:?
- rows?in?set?(0.00?sec)?
MYSQL應用?
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/5578.html