MySQL多源复制配置实施步骤
admin
2023-05-23 14:42:31
0

本文主要给大家介绍MySQL多源复制配置实施步骤,文章内容都是笔者用心摘选和编辑的,具有一定的针对性,对大家的参考意义还是比较大的,下面跟笔者一起了解下MySQL多源复制配置实施步骤吧。

多源复制的意义

   1.可以在一个从库上对多个云服务器的数据库进行汇总,或者对一个数据库的分库分表进行汇总。

   2.集约使用从库云服务器的硬件资源,毕竟弱一个数据库业务量较小确占用整个云服务器资源是不经济的。

   3.更方便的对个业务库进行数据备份,优化数据库备份脚本编写逻辑

拓补图

MySQL多源复制配置实施步骤


实施步骤

   1.备份主库上的数据,考虑到gtid的问题建议只采用mysqldump程序进行备份

centos:#mysqldump --login-path=3306 \ #mysql官方工具都支持login-path快速登录
         --single-transaction \ #事务一致性备份,防止备份完整性被事务一致性破坏
         --master-data=2 \ #在备份文件的头部加一句change master to pos的注释语句
          -A >ip06p3306.sql #备份所有数据库


  2.将导出的文件传输到从库的云服务器上

   centos_ip06:#scp ip06p3306.sql root@192.168.1.11:/root/
   centos_ip31:#scp ip31p3306.sql root@192.168.1.11:/root/

   3.将主库的备份文件导入到从库上

   centos:#mysql --login-path=3306 \
             -f 

  4.从两份备份文件的头部查看两个主库备份时执行到的GTID 

    MySQL多源复制配置实施步骤

   centos:#less ip06p3306.sql|grep PURGED #得到GTID_ip06
   centos:#less ip31p3306.sql|grep PURGED #得到GTID_ip31

   5.重新设置从库的GTID(在从库上执行)

   mysql>reset master;
   mysql>set global gtid_purged='GTID_ip06,GTID_ip31';

   6.将从库的指向各自的主库

   

      mysql>change master to \           
      master_host='192.168.1.6',master_port=3306,\
      master_user='repl',master_password='123456', \    
      master_auto_postion=1 \自动对齐GTID,从库宕机重启后,删除未执行relaylog,重新拉取        for channel 'master_3306';为这个主设定一个频道名,可设为易于辨认的名字

 7.设置不方便同步的库:(如会导致复制出重复用户的mysql库) 

   但sys,performance,information为模式或者视图一样的存在,数据在读取时即时生成,不真正存储数据,可以不过滤

  

 mysql>stop slave sql_thread;#停止从库的重放进程,比停止整个从库要方便的多
    mysql>change replication filter \
    replicate_ignore_db=(mysql,db1);\#把复制的库放在括号里,并用,分隔
    mysql>start slave sql_thread;

 8.查看信息:  

   

mysql> show slave status\G
    *************************** 1. row ***************************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 192.168.1.6
    Master_User: repl
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysql-bin.000016
    Read_Master_Log_Pos: 194
    Relay_Log_File: localhost-relay-bin-master_3306.000033
    Relay_Log_Pos: 367
    Relay_Master_Log_File: mysql-bin.000016
    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: 194
    Relay_Log_Space: 803
    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: 13306
    Master_UUID: 449fdd93-1b80-11e7-b054-000c29aa1d65
    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: 066c3194-2b4b-11e7-b67b-000c290b6ef0:1-2951823,
                         449fdd93-1b80-11e7-b054-000c29aa1d65:1-140,
                         efa1d12e-3c56-11e7-a99e-000c29ba498d:1-481
    Auto_Position: 1
    Replicate_Rewrite_DB: 
    Channel_Name: master_3306
    Master_TLS_Version: 
      *************************** 2. row ***************************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 192.168.1.31
    Master_User: repl
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysql-bin.000026
    Read_Master_Log_Pos: 375018221
    Relay_Log_File: localhost-relay-bin-master_zabbix.000032
    Relay_Log_Pos: 375018394
    Relay_Master_Log_File: mysql-bin.000026
    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: 375018221
    Relay_Log_Space: 375018619
    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: 313306
    Master_UUID: 066c3194-2b4b-11e7-b67b-000c290b6ef0
    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: 066c3194-2b4b-11e7-b67b-000c290b6ef0:2310554-2951823
    Executed_Gtid_Set: 066c3194-2b4b-11e7-b67b-000c290b6ef0:1-2951823,
              449fdd93-1b80-11e7-b054-000c29aa1d65:1-140,
              efa1d12e-3c56-11e7-a99e-000c29ba498d:1-481
    Auto_Position: 1
    Replicate_Rewrite_DB: 
    Channel_Name: master_zabbix
    Master_TLS_Version: 
          2 rows in set (0.01 sec)

看完以上关于MySQL多源复制配置实施步骤,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。

相关内容

热门资讯

赋能全域数据互通,“郑数登”入... 【大河财立方 记者 李雯雯】5月19日,大河财立方记者从郑州数据交易中心获悉,由河南省发展改革委、中...
河南文旅,“留量时代” 【大河财立方 记者 朱娟】初夏微风,轻拂过中原,吹动文旅潮涌不息。从龙门石窟的千年石刻到洛邑古城的汉...
从机甲量产到AI适配 人形机器... 载人变形机甲量产落地,人形机器人接入AI智能体,机器人动作大模型面世……近期,我国人形机器人领域迎来...
鑫宏业获得实用新型专利授权:“... 证券之星消息,根据天眼查APP数据显示鑫宏业(301310)新获得一项实用新型专利授权,专利名为“抗...
客运航司上市有望破冰!长龙航空... 【大河财立方消息】 时隔8年,A股或再迎来一家客运航空公司。近日,证监会官网显示,浙江长龙航空股份有...
湖南省拟发行34.12亿元地方... 【大河财立方消息】 5月19日,湖南省财政厅发布通知,决定发行2026年湖南省政府专项债券(十至十一...
中央生态环保督察公布辽宁、吉林... 第三轮第六批中央生态环境保护督察今天(5月19日)集中公布辽宁、吉林、黑龙江和广西四省区典型案例。辽...
2026年成都市科技活动周即将... 记者从成都市科技局获悉,5月23日晚,2026年四川省科技活动周暨蓉城科学之夜启动仪式将在成都天府艺...
河南制造,“小满时刻” 【大河财立方 记者 王磊彬 文图】立夏之后,小满将至。中原沃野之上,千万亩小麦正进入籽粒灌浆、日渐充...
败诉后,马斯克表示“不服” 就美国企业家埃隆·马斯克针对开放人工智能研究中心(OpenAI)的诉讼,加利福尼亚州奥克兰市一家联邦...