实例MySQL8双主:Master-->master

Master1: centos7、mysql8.0.12、10.0.103.102

Master2: centos7、mysql8.0.12、10.0.101.193

安装步骤请参考MySQL8安装

Master1 my.cnf配置如下:

server-id=1     # 节点ID,确保唯一

log-bin=mysql-bin    #开启mysql的binlog日志功能,binlog日志位置

read-only=0

#不同步哪些数据库,不生成日志文件的数据库,多个忽略数据库可以用逗号拼接,或者复制这句话,写多行

binlog-ignore-db=mysql

binlog-ignore-db=information_schema

binlog-ignore-db=performance_schema

auto-increment-increment = 2

auto-increment-offset = 1

relay-log=mysqld-relay-bin

log-slave-updates

binlog-do-db = game   #只同步哪些数据库,除此之外,其他不同步  

sync_binlog = 1         #控制数据库的binlog刷到磁盘上去 , 0不控制,性能最好,1每次事物提交都会刷到日志文件中,性能最差,最安全

binlog_format = mixed   #binlog日志格式,mysql默认采用statement,建议使用mixed

expire_logs_days = 7                           #binlog过期清理时间

max_binlog_size = 100m                    #binlog每个日志文件大小

binlog_cache_size = 4m                        #binlog缓存大小

max_binlog_cache_size= 512m              #最大binlog缓存大

auto-increment-offset = 1     #自增值的偏移量

auto-increment-increment = 1  #自增值的自增量

slave-skip-errors = all    #跳过从库错误

Master2 my.cnf配置如下:

server-id=2

log-bin=mysql-bin

read-only=0

#不同步哪些数据库

binlog-ignore-db=mysql

binlog-ignore-db=information_schema

binlog-ignore-db=performance_schema

auto-increment-increment = 2

auto-increment-offset = 2

relay-log=mysqld-relay-bin

log-slave-updates

两边都创建操作用户

create user user_master@'%' identified by 'QH3-d6cHL9NNEQ4K';

grant all privileges on *.* to user_master@'%' with grant option;

flush privileges;

Master1上查看bin和pos:show master status;

到master2上:

change master to master_host='10.0.103.102',master_user='user_master',master_password='QH3-d6cHL9NNEQ4K',master_log_file='mysql-bin.000001',master_log_pos=155;

start slave;

show slave status;

参数解释:MASTER_HOST:设置要连接的主服务器的ip地址

MASTER_USER:设置要连接的主服务器的用户名

MASTER_PASSWORD:设置要连接的主服务器的密码

MASTER_LOG_FILE:设置要连接的主服务器的bin日志的日志名称,即第3步得到的信息

MASTER_LOG_POS:设置要连接的主服务器的bin日志的记录位置,即第3步得到的信息(这里注意,最后一项不需要加引号。否则配置失败)

在master2上:show master status;

在master1上

change master to master_host='10.0.101.193',master_user='user_master',master_password='QH3-d6cHL9NNEQ4K',master_log_file='mysql-bin.000001',master_log_pos=155;

start slave;

show slave status;

如下图,均为Yes表示成功。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值