mysql5.7 主从复制简单环境搭建以及开启半同步复制等配置

本文档详细介绍了如何在MySQL5.7环境下搭建主从复制,并着重讲解了如何配置半同步复制和并行复制组提交。首先,配置主从库的基本步骤包括修改my.cnf,授权,启动复制等。然后,通过安装和启用rpl_semi_sync_master和rpl_semi_sync_slave插件实现半同步复制,设置延迟时间。最后,设置并行复制的组提交,调整相关参数以优化性能。
摘要由CSDN通过智能技术生成
  1. 准备两台mysql服务器环境

    参考 https://blog.csdn.net/qq_42303467/article/details/122137696

  2. 配置主库 ip 192.168.95.130

    修改/etc/下的my.cnf文件

    vim /etc/my.cnf

    my.cnf 配置如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.

log_bin=mysql-bin #开启binlog功能

server-id=1 #与从机的id不可相同

sync-binlog=1 #每次执行写入操作与磁盘同步 

binlog-ignore-db=performance_schema  #指定不同步的从库的系统数据库
binlog-ignore-db=information_schema
binlog-ignore-db=sys

#binlog-do-db=mysql  #指定只同步的从库的数据库(可以是任意的) 不指定默认全部

#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
  1. 重启主库mysql

    systemctl restart mysqld

  2. 登录主库

    mysql -uroot -p

  3. 配置主库给从库增加同步授权

    mysql> grant replication slave on *.* to 'root'@'%' identified by 'root';

    mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';

    mysql>flush privileges;

  4. 查看 主库状态

    mysql>show master status;

+------------------+----------+--------------+-------------------------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB                          | Executed_Gtid_Set |
+------------------+----------+--------------+-------------------------------------------+-------------------+
| mysql-bin.000001 |      869 |              | performance_schema,information_schema,sys |                   |
+------------------+----------+--------------+-------------------------------------------+-------------------+
1 row in set (0.00 sec)

  1. 配置从库 ip192.168.95.132

    vim /etc/my.cnf

    从库的binlog可以不需要开启

    配置如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
server-id=2  #设置serverid

relay_log=mysql
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值