MySQL数据库主主复制原理及配置

MySQL的双主复制其实就是为主的时候同时也是从,为从是也是主。

实验环境

Master1:192.168.200.12
Master2:192.168.200.13

准备工作

所有机器关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0

Master1配置

修改配置文件

[root@localhost ~]# 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                            #奇数ID

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'		##连接时执行的SQL
character-set-server=utf8		##服务端默认字符集
wait_timeout=1800		##请求的最大连接时间
interactive_timeout=1800		##和上一参数同时修改才会生效
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES		##sql模式
	
relay-log=relay-log-bin			##开启中继日志
relay-log-index=slave-relay-bin.index
[root@localhost ~]# systemctl restart mariadb

创建授权账号

[root@localhost ~]# mysql
MariaDB [(none)]> grant replication slave on *.* to 'repl'@'192.168.200.13' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show master status;
+---------------------+----------+--------------+------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-----
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值