MySql主从同步

MySql—Master—Slave

Linux配置mysql主从

Ip:192.168.0.1 Master
Ip:192.168.0.2 Slave

配置文件
vim /etc/my.cnf
添加如下内容到my.cnf

  • Master(主) IP:192.168.0.1
[mysqld]
server-id=1   #必须。设置服务器id,为1表示主服务器。
log_bin=mysql-bin  #必须。启动MySQ二进制日志系统。
binlog-do-db=test#需要同步的数据库名,如果有多个数据库,配置多行
binlog-ignore-db=mysql   #不同步mysql系统数据库。

  • Slave(从) IP:192.168.0.2
[mysqld]
server-id=2   #必须。设置服务器id,为2表示从服务器。
log_bin=mysql-bin  #不必须。启动MySQ二进制日志系统。
binlog-do-db=test#需要同步的数据库名,如果有多个数据库,可重复此参数,配置多行
binlog-ignore-db=mysql   #不同步mysql系统数据库。

** 修改完my.cnf重启数据库**
重启后执行主从配置命令

Ip:192.168.0.2执行命令

[root@F8SFRZ ~]$mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 909
Server version: 10.1.36-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(mysql)]> slave stop;
MariaDB [(mysql)]> change master to master_host='192.168.0.1',master_user='admin',master_password='admin',master_log_file='mysql-bin.000001' ,master_log_pos=0;
MariaDB [(mysql)]> slave start; 
MariaDB [(mysql)]> show slave status;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.1
                  Master_User: root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000004
          Read_Master_Log_Pos: 983
               Relay_Log_File: mysqld-relay-bin.000007
                Relay_Log_Pos: 834
        Relay_Master_Log_File: mysql-bin.000004
             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: 983
              Relay_Log_Space: 1623
              Until_Condition: None
.....
.....
.....
省略
-------------------------------------------------------------------------------
Slave_IO_Running、Slave_SQL_Running 等于Yes表示配置成功

如果出现No了,请尝试执行

MariaDB [(mysql)]> stop slave;set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;START SLAVE;

搞定!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

最是书香能致远

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值