mysql主从配置,多级配置(从库到总部库)

 

 

 

实现步骤如下:

              
1. 将主数据库设置为只读模式
 

  show variables like '%read_only%'   
   set @@global.read_only=ON


   
   创建一个复制用户
 

 grant replication slave on *.* to repl@'%' identified by 'test2018' ;

2. 关闭Mysql服务

3. 将data目录下的db_pldb文件夹以及ibdata1文件压缩成 data压缩包

4. 修改主数据库的配置文件 my.ini
   
 

 server-id=2
   log-bin=mes-bin-2 
   binlog-do-db=db_test
   binlog-ignore-db=mysql
   binlog_cache_size=30M
   binlog_format=mixed
   binlog_row_image=minimal   
   max_binlog_size=300M
   expire_logs_days=7
   sync_binlog=1
   gtid_mode=on
   enforce-gtid-consistency=true


 
5. 启动Mysql服务

6. 在主数据上执行 reset master, 在此处主数据库的配置完成

7. 将data压缩包 传输到 从数据库的服务器上

8. 解压压缩包,将文件放置到data目录下

9. 启动从数据库服务

   创建一个复制用户
 

 grant replication slave on *.* to repl@'%' identified by 'test2018' ;

10. 新建db_test_backup数据库,并将db_test数据库中的数据全部拷贝到db_test_backup数据库中

11. 删除db_test库

12. 关闭从数据库服务

13. 配置从数据库
   

 server-id=1002
    log-bin=mes-bin-1002
    binlog-do-db=db_test_backup
    binlog-ignore-db=mysql
    binlog_cache_size=30M
    binlog_format=mixed
    max_binlog_size=300M
    expire_logs_days=7
    log-slave-updates=ON
    master-info-repository=TABLE
    relay-log-info-repository=TABLE
    max_relay_log_size=300M
    relay_log=mes-relay-10023
    #skip-slave-start=1
    gtid-mode=ON
    enforce-gtid-consistency=true
    sync-binlog=1
    replicate-rewrite-db="db_test->db_test_backup"

14. 启动从数据库服务

15.

reset master
    reset slave

16.

change master to master_host='127.0.0.1',master_port=3306,
    master_user='repl',master_password='test2018',master_auto_position=1;

17.

 start slave  
    show slave status,

到此工厂从数据库配置完毕

 从数据库到总部配置

19. 总部配置 

   sync_binlog=1
    gtid_mode=on
    enforce-gtid-consistency=true
    master-info-repository=TABLE
    relay-log-info-repository=TABLE
    max_relay_log_size=300M
    relay_log=mes-relay-20023
    skip-slave-start=1

20. 将工厂从数据库设置为只读模式

 show variables like '%read_only%'   
   set @@global.read_only=ON
   创建一个复制用户
   grant replication slave on *.* to mesrepl@'%' identified by 'Mes20180306' ;

   set global read_only=1; 
show global variables like "%read_only%";
-- 锁表
flush tables with read lock;
-- 解锁
unlock tables;

21.在总部数据库传输工厂从数据库数据(与从数据库名保持一致);

22.reset master;

23。

change master to master_host='127.0.0.1',master_port=3306,
    master_user='repl',master_password='test2018',master_auto_position=1 for channel 'db_test_backup';

24.start slave;

25.show slave status;

 

 

 

转载于:https://my.oschina.net/lyleluo/blog/2049945

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值