mysql主主同步稳定吗_mysql主主同步

第一台机器主

[root@master ~]# vim /etc/my.cnf

[mysqld]

server-id=1

log-bin=mysql-binlog

log-slave-updates=true

max_binlog_size=1024M

auto_increment_offset = 1

auto_increment_increment = 2

replicate-ignore-db = information_schema

replicate-ignore-db = performance_schema

replicate-ignore-db = test

replicate-ignore-db = mysql

max_connections = 3000

max_connect_errors = 30

skip-character-set-client-handshake

init-connect=‘SET NAMES utf8‘

character-set-server=utf8

wait_timeout=1800

interactive_timeout=1800

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

relay-log=relay-log-bin

relay-log-index=slave-relay-bin.index

[root@master ~]# systemctl restart mariadb

[root@master ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.56-MariaDB MariaDB Server

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

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

MariaDB [(none)]> grant replication slave on *.* to ‘repl‘@‘192.168.30.24‘identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> show master status;

+---------------------+----------+--------------+------------------+

| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------------+----------+--------------+------------------+

| mysql-binlog.000004 |      483 |              |                  |

+---------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

第2台

[root@master1 ~]# vim /etc/my.cnf

[mysqld]

server-id=2

log-bin=mysql-binlog

log-slave-updates=true

max_binlog_size=1024M

auto_increment_offset = 2

auto_increment_increment = 2

replicate-ignore-db = information_schema

replicate-ignore-db = performance_schema

replicate-ignore-db = test

replicate-ignore-db = mysql

max_connections = 3000

max_connect_errors = 30

skip-character-set-client-handshake

init-connect=‘SET NAMES utf8‘

character-set-server=utf8

wait_timeout=1800

interactive_timeout=1800

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

relay-log=relay-log-bin

relay-log-index=slave-relay-bin.index

[root@master1 ~]# systemctl restart mariadb

[root@master1 ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.56-MariaDB MariaDB Server

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

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

MariaDB [(none)]> grant replication slave on *.* to ‘repl‘@‘192.168.30.25‘identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show master status;

+---------------------+----------+--------------+------------------+

| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------------+----------+--------------+------------------+

| mysql-binlog.000001 |      483 |              |                  |

+---------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

测试环境,可以保证没数据写入,否则需要的步骤是:先masterA锁表-->masterA备份数据-->masterA数据表--> masterB导入数据--> masterB设置主从-->查看主从

第1台机器

[root@master ~]# mysql -u root

MariaDB [(none)]> stop slave;

MariaDB [(none)]> change master tomaster_host=‘192.168.30.24‘,master_port=3306,master_user=‘repl‘,master_password=‘123456‘,master_log_file=‘mysql-binlog.000001‘,master_log_pos=483;

MariaDB [(none)]> start slave;

MariaDB [(none)]> show slave status\G;

第2台机器

[root@master1 ~]# mysql -u root

MariaDB [(none)]> stop slave;

MariaDB [(none)]> change master to

-> master_host=‘192.168.30.25‘,master_port=3306,master_user=‘repl‘,master_password=‘123456‘,master_log_file=‘mysql-binlog.000004‘,master_log_pos=483;

MariaDB [(none)]> start slave;

MariaDB [(none)]> show slave status\G;

第一台机器

MariaDB [(none)]> create database test01;

第二台机器查看是否同步

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sampdb             |

| test               |

| test01             |

+--------------------+

第二台机器

MariaDB [(none)]> create database test02;

查看第一台机器

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sampdb             |

| test               |

| test01             |

| test02             |

+--------------------+

7 rows in set (0.00 sec)

mysql主主同步

标签:server-id   init   names   query   ons   sys   ini   mysql主主同步   base

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:https://www.cnblogs.com/zc1741845455/p/10921253.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值