mysql5.6 replication_MySQL 5.6 Replication
打开mysql主页,满篇介绍mysql5.6版本有多好,多牛。后来浏览了5.6的更新说明,说是强化了replication,还有人测试开启replication对性能影响不大,不像以前,影响性能明显。反而性能更好?那个叫mysql中国的网站测试说的。官网有说多线程啥的进行复制,好吧。我信了。
但是安装网上老的配置方法配置主从模式失败,服务起不来,说找不到pid什么文件,错误已经忘啦~~不好意思。
于是乎,在官方下载最新的安装文档...全英文...一口一口的啃。
终于在1个小时前配置好了,是双主互备模式。master==master.
整理下配置方法。
安装mysql5.6.9(×××那个网站没有提供最新的5.6.10版本,而我又不想装RPM包,你懂的)。安装在这里略过,只要看解压后里面的INSTALL文件安装提示来就可以了。
我把mysql安装到了/usr/local/mysql目录,装完之后,有个my.cnf在/usr/local/mysql目录下面。
这个就是配置文件了,打开一看,里面就有一行...
-----------------下面我们开始配置-------------
两台服务器:mysql-m1 192.168.0.140
mysql-m2 192.168.0.141
打开mysql-m1的my.cnf文件,添加如下代码:
binlog-format=ROW
log-slave-updates=true
gtid-mode=on # GTID only
enforce-gtid-consistency=true # GTID only
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=1
report-port=3306
port=3306
log-bin=binlog
report-host=192.168.0.140
肯定有人好奇,为啥要加这些代码?
好吧,我也不知道,官方就这么说的。(开玩笑了)。我把个个参数的意思原汁原味的写出来:
• binlog-format: row-based replication is selected in order to test all of the MySQL 5.6
optimisations
• log-slave-updates, gtid-mode, enforce-gtid-consistency, report-port and
report-host: used to enable Global Transaction IDs and meet the associated prerequisites
• master-info-repository and relay-log-info-repository: are turned on to enable
the crash-safe binlog/slave functionality (storing the information in transactional tables rather
than flat files)
• sync-master-info: set to 1 to ensure that no information is lost
• slave-parallel-workers: sets the number of parallel threads to be used for applying
received replication events when this server acts as a slave. A value of 0 would turn off the
multithreaded slave functionality; if the machine has a lot of cores and you are using many
databases within the server then you may want to increase this value in order to better exploit
multi-threaded replication
• binlog-checksum, master-verify-checksum and slave-sql-verify-checksum:
used to enable all of the replication checksum checks
• binlog-rows-query-log-events: enables informational log events (specifically, the
original SQL query) in the binary log when using row-based replication – this makes
troubleshooting simpler
• log-bin: The server cannot act as a replication master unless binary logging is enabled. If
you wish to enable a slave to assume the role of master at some point in the future (i.e. in the
event of a failover or switchover), you also need to configure binary logging. Binary logging
must also be enabled on the slave(s) when using Global Transaction IDs.
• server-id: The server_id variable must be unique amongst all servers in the replication
topology and is represented by a positive integer value from 1 to 2
32
好了,上面的参数都知道什么意思了吧。
接下来,我们同样设置第二台服务器:
binlog-format=ROW
log-slave-updates=true
gtid-mode=on # GTID only
enforce-gtid-consistency=true # GTID only
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=2
report-port=3306
port=3306
log-bin=binlog
report-host=192.168.0.141
注意,server-id=2,另外,report-host也改下。
这两个配置文件改好之后重启服务器。
重启完服务器之后,登录第二台服务器mysql-m2
登录mysql
mysql -u root -p
输入完用户名和密码之后:
> CHANGE MASTER TO MASTER_HOST=192.168.0.140, MASTER_USER='repl_user',
MASTER_PASSWORD='billy';
> START SLAVE;
这样主从模式就做好了主-----》从
-----------------------------------
我们在第一台服务器上设置可远程登录账户:
先登录mysql服务器:
>Grant all privileges on *.* to 'admin'@'%' identified by '123456' with grant option;
红色字体分别为账户和密码。
同样的,第二台服务器也这么操作。
然后,我们在主服务器(mysql-m1)的test数据库下面建立一个表测试同步情况:
登录mysql服务器:mysql -u root -p
>use test;(装好后,mysql默认自带)。
>create table abc(a int,b int,c int);
创建好后插入数据。
>insert into abc values(1,2,3);
多执行几次
然后select * from abc;
查看数据插入进去了没有。(我后面有自己插入了几行)。
mysql> select * from acc;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 2 | 2 | 2 |
| 2 | 2 | 2 |
| 2 | 2 | 2 |
+------+------+------+
登录mysql-m2,查看是否有数据同步过来。
同步过来了就是ok的了。
-------------------------------------
官方的文档只说了主从模式,我查了一下,要做双主模式,必须开启log-slave-updates=true这个选项。
我看了看两台服务器的配置文件都有这个。
然后呢,我自己试了一下。
登录主服务器---mysql-m1
登录mysql ----mysql -u root -p
输入密码
执行:
> CHANGE MASTER TO MASTER_HOST=192.168.0.141, MASTER_USER='admin',
MASTER_PASSWORD='123456';
> START SLAVE;
没想到,真的就可以,没报错。
>show slave status\G;
两台服务器都能查询出来信息。
===================总结=================
官方这个文档我是明白了。
它让每个slave都有当master的机会,如果一个master宕机了,
执行:
> CHANGE MASTER TO MASTER_HOST=192.168.0.*, MASTER_USER='repl_user',
MASTER_PASSWORD='billy';
> START SLAVE;
这个操作,只要换个IP地址,可以把任何一台从机变成主机,当主机启动之后,再执行:
> CHANGE MASTER TO MASTER_HOST=192.168.0.MASTER_IP, MASTER_USER='repl_user',
MASTER_PASSWORD='billy';
> START SLAVE;
这样主从切换来回自如。
不过,我真的不知道类似于heartbeat的功能有木有~~~~我不像业务中断,难道要在master上面做heartbeat?
mysql5.6 replication_MySQL 5.6 Replication相关推荐
- mysql5.5 replication_mysql5.5 master-slave(Replication)配置
一主一从: Master: OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.2 Slave: OS:centos release 5.6 DB ...
- mysql5.6semi plugin_mysql5.6 semi replication 半同步复制配置(示例代码)
--###半同步配置 --1.插件位置 mysql> show variables like 'plugin_dir' -> ; +---------------+------------ ...
- MySQL5.5复制新特性
MySQL5.5复制新特性 一.MySQL5.5复制改进 MySQL5.5版本对MySQL Replication进行了多项的改良,以提供数据的完整性,性能和应用灵活性更高水平. 1.Semisync ...
- mysql slave 配置_【mysql5.6】 数据库主从(Master/Slave)配置记录
freddon 发表于2018-04-01 阅读 661 | 评论 0 前一段时间迫于服务器的捉急内存,将redis数据库停掉了,鉴于redis的主从配置,在centos配置下mysql记录下过程. ...
- mysql 5.5 特性_MySQL5.5复制新特性
MySQL5.5复制新特性 一.MySQL5.5复制改进 MySQL5.5版本对MySQL Replication进行了多项的改良,以提供数据的完整性,性能和应用灵活性更高水平. 1.Semisync ...
- MySql优化(六)MyCat中间件
MyCat介绍 首先MyCat是什么简单的介绍下 一个彻底开源的,面向企业应用开发的大数据库集群 支持事务.ACID.可以替代MySQL的加强版数据库 一个可以视为MySQL集群的企业级数据库,用来替 ...
- MySQL5.7 Replication主从复制配置教程
最近配置mysql5.7主从复制的时候碰到了些问题,老老实实按老版本的步骤配置会有错误,后来自己查看了官方文档,才解决了问题,在这里总结一下5.7的配置步骤, 大体步骤跟老版本的还是一样的,只是有一些 ...
- mysql5.6 replication_MySQL5.6 Replication主从复制(读写分离) 配置完整版
MySQL5.6主从复制(读写分离)教程 1.MySQL5.6开始主从复制有两种方式: 基于日志(binlog): 基于GTID(全局事务标示符). 需要注意的是:GTID方式不支持临时表!所以如果你 ...
- mysql5.6.37 主从同步_MySQL5.6 Replication主从复制(读写分离) 配置完整版
1.MySQL5.6开始主从复制有两种方式: 基于日志(binlog): 基于GTID(全局事务标示符). 需要注意的是:GTID方式不支持临时表!所以如果你的业务系统要用到临时表的话就不要考虑这种方 ...
最新文章
- 在vc6控制台程序中如何调用运行ImageMagick命令行工具
- javascript函数式_JavaScript中的函数式编程—结合实际示例(第1部分)
- python whl是什么文件
- Spark的RDD转换算子
- C语言实现割线法求零点以及详解割线法
- 解决内网搭建本地yum仓库。
- pt939g联通_尝试修改友华PT939G的省份设置,成功!
- 学习Spring Boot:(六) 集成Swagger2
- 使用flags定义命令行参数
- 怎么把pdf拆分成一页一页的?
- ssl证书在哪?如何查看ssl证书内容
- 【小程序】小程序里跳转网页链接
- matlab图片投稿,投稿时图片DPI的设置及相关心得
- 辐射76服务器位置,辐射76快速升级位置分享 前中期哪些位置好升级
- 微信小程序修改数组中的元素_微信小程序——this.setData()动态修改数组中的某一值...
- Android 使用 Ant 批量打包
- android layout文件夹下新建子文件夹 及解决文件夹爆红
- 35_Pandas计算满足特定条件的元素的数量
- 计算机学校教师培训方案,教师培训电脑多媒体实施方案
- STM32+LD-1501舵机控制and MG996R舵机
热门文章
- DPM灾难切换应用场景
- 大屏监控系统实战(14)-24小时得票数量统计曲线制作
- mac下的secureCRT.8的设置
- java程序员饱和了吗?
- 使用静态内置类实现线程安全的单例设计模式
- 开灯关灯java script_Jquery实现视频播放页面的关灯开灯效果
- windows下sublime通过sftp扩展上传文件到linux服务器上
- 【转】ORACLE_SID、INSTANCE_NAME、DB_NAME
- windows mobile 开发 web service 未能建立与网络的连接、无法连接到远程服务器
- 【读书笔记】.NET本质论第四章-Programming with Type(Part Two)