首页 > 数据库 > MySQL > 正文

MySQL异步复制和半同步复制怎么达成

2024-07-24 12:33:07
字体:
来源:转载
供稿:网友
  这篇文章主要介绍“MySQL异步复制和半同步复制怎么实现”,在日常操作中,相信很多人在MySQL异步复制和半同步复制怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MySQL异步复制和半同步复制怎么实现”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
 
  异步复制环境的规划:
 
  master(docker),端口3310
  slave(docker),端口3311
  master的配置
  配置文件my.cnf
 
  $ sudo cat /home/mysql/docker-data/3311/conf/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
  #
  # 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=/home/mysql/docker-data/3307/data
  #socket=/home/mysql/docker-data/3307/mysql.sock
  character_set_server=utf8
  init_connect='SET NAMES utf8'
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  #log-error=/home/mysql/docker-data/3307/logs/mysqld.log
  #pid-file=/home/mysql/docker-data/3307/mysqld.pid
  lower_case_table_names=1 # 表名是否小写
  server-id=1403311
  log-bin=mysql-bin # 开启binlog
  binlog-format=ROW # binlog的格式
  auto_increment_increment=1 # 自增的步长,适用于主主复制,为了避免id冲突,步长设置为master的个数
  auto_increment_offset=1 # 自增的偏移,主主复制每个master的偏移需要不一致
  # binlog-do-db=mstest      # 要同步的数据库
  # binlog-ignore-db=mysql  # 要忽略的数据库
  #rpl_semi_sync_master_enabled=1
  #rpl_semi_sync_master_timeout=10000
  启动mysql:
 
  $ docker run --name mysql3310 -p 3310:3306 --privileged=true -ti -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=order -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -v /home/mysql/docker-data/3310/conf:/etc/mysql/conf.d -v /home/mysql/docker-data/3310/data/:/var/lib/mysql -v /home/mysql/docker-data/3310/logs/:/var/log/mysql -d mysql:5.7
  创建用于同步的用户:
 
  mysql> GRANT REPLICATION SLAVE,FILE,REPLICATION CLIENT ON *.* TO 'repluser'@'%' IDENTIFIED BY '123456';
  Query OK, 0 rows affected, 1 warning (0.01 sec)
  mysql> FLUSH PRIVILEGES;
  Query OK, 0 rows affected (0.01 sec)

(编辑:武林网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表