mysql主主双向主从M-M(互为主从)

M-M 双主互备 (互为主从)

在这里插入图片描述
这种的搭建就是在主从的基础上从新配置一次就可以,很简单
10.10.100.28主
10.10.100.22从
主从已经是搭建好,现在把从变成主,把主变成从
搭建好的效果就是两边都可以写,
开始配置
授权

mysql> grant replication slave on *.* to slave@'10.10.100.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
如果不符合密码要求修改如下(5.7版本)
mysql> set global validate_password_policy=0;  #定义复杂度
mysql> set global validate_password_length=1;  #定义长度 默认是8
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

修改配置文件,启动二进制日志

[root@localhost ~]# vim /etc/my.cnf
server-id=2
log-bin=mysql-bin-slave
binlog-do-db=test
binlog-ignore-db=mysql

重启服务

[root@localhost ~]# systemctl restart mysqld

查看master状态

mysql> show master status;
+------------------------+----------+--------------+------------------+-------------------+
| File                   | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------------+----------+--------------+------------------+-------------------+
| mysql-bin-slave.000001 |      154 | test         | mysql            |                   |
+------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

测试连接

[root@localhost ~]# mysql -uslave -p123456 -h10.10.100.28
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.28-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> stop slave;   #停止从服务
Query OK, 0 rows affected, 1 warning (0.00 sec)

将远程连接用户写到数据库里面
mysql> change master to master_host='10.10.100.28',master_user='slave',master_password='123456';
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> flush privileges;      #刷新权限表
mysql> start slave;      启动从服务
Query OK, 0 rows affected (0.01 sec)

查看从状态

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.100.28
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin-slave.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 379
        Relay_Master_Log_File: mysql-bin-slave.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

看见两个yes,就搭建成功了

插入数据测试数据同步

mysql> insert into test values (4,'test23');
Query OK, 1 row affected (0.00 sec)

查看

mysql> select * from test;
+------+--------+
| id   | name   |
+------+--------+
|    1 | dz     |
|    1 | ddz    |
|   44 | ddz    |
|   33 | slave  |
|    4 | test23 |
+------+--------+
5 rows in set (0.00 sec)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Rio520

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

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

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

打赏作者

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

抵扣说明:

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

余额充值