MySQL5.7多源复制Mysql入门

MySQL5.7多源复制Mysql入门,第1张

概述介绍《MySQL5.7多源复制Mysql入门》开发教程,希望对您有用。

《MysqL5.7多源复制MysqL入门》要点:
本文介绍了MysqL5.7多源复制MysqL入门,希望对您有用。如果有疑问,可以联系我们。

导读:MysqL5.7开始支持多源复制,也就是多主一从的复制架构:使用多源复制的考虑:1、灾备作用:将各个库汇总在一起,就算是其他库都挂了(整个机房都无法连接了),还有最后一个救命稻草; MysqL5.7开始支持多源复制,也就是多主一从的复制架构:



使用多源复制的考虑:
1、灾备作用:将各个库汇总在一起,还有最后一个救命稻草;
2、备份:直接在这个从库中做备份,不影响线上的数据库;
3、减少成本:不需要每个库都做一个实例,也减少了DBA的维护成本;
4、数据统计:后期的一些数据统计,需要将所有的库汇总在一起.
... ...

实验环境:
Master1:10.157.26.132:3307
Master2:10.157.26.133:3307
Slave:10.157.26.134:3307
多源复制是支持GTID和binlog+position,我这里是GTID复制.

MysqL5.7的安装这里不再介绍,可以查看http://www.cnblogs.com/lizhi221/p/6813907.HTML

一、配置文件:

Master1和Master2:

#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 

Slave:

#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'
三:从库启动复制:

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_user='sampson_133',master_password='sampson_133',master_auto_position=1 for channel 'Master_133' MysqL>start slave; 
也可以start slave for channel 'Master_132 '启动单个channel的复制.

四:查看slave状态
【也可以直接show slave status for channel 'Master_132' \G查看各个channel的复制状态】

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) 
通过查看performance_schema相关的表查看同步状态:

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) 

五、数据同步检查:
Master1建库建表并插入数据:

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,(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,'133'),'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应用 

总结

以上是内存溢出为你收集整理的MySQL5.7多源复制Mysql入门全部内容,希望文章能够帮你解决MySQL5.7多源复制Mysql入门所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1160297.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存