mysql gitd 主从搭建_Yii2 优雅的 Active Record - SegmentFault 思否
说明:
环境
mysql-master:172.16.200.43
mysql-slave:172.16.200.44
系统:centos7
版本:MySQL5.6.35
一、基于GTID复制环境的搭建前提
主从环境的搭建和5.5没有什么区别,唯一需要注意的是:开启GTID需要启用这三个参数:
#GTID
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1
gtid-mode用来设置是否开启GTID功能,如果要开启GTID功能,需要同时开启log-bin和log_slave_updates功能,另外还需要开启enforce_gtid_consistency功能。gtid_mode参数可以设置为on、off、upgrade_step_1、upgrade_step_2四种值,其中upgrade_step_1和upgrade_step_2是给将来mysql可能的新功能预留的,对当前的myql没有任何意义。同时,mysql建议在mysql_upgrade的时候,关闭gtid_mode功能和enforce_gtid_consistency功能,因为Mysql在upgrade期间可能会操作非事务的MyISAM存储引擎表,会引起报错。
二、配置步骤
1、43上面授权44从库的账号
MySQL [(none)]> grant replication slave on *.* to 'slave'@'172.16.200.44' identified by '000000';
MySQL [(none)]> flush privileges;
2、配置主从同步
MySQL [(none)]> stop slave;
MySQL [(none)]> CHANGE MASTER TO MASTER_HOST='172.16.200.43', MASTER_USER='slave', MASTER_PASSWORD='000000', MASTER_AUTO_POSITION=1;
MySQL [(none)]> start slave;
3、关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
三、测试跳过一个事务
1、 43上面新建库test
2、43上面新建表info_area
CREATE TABLE `info_area` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '地区ID',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '名称',
`rel_id` varchar(50) NOT NULL DEFAULT '' COMMENT '关系ID',
`pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父ID',
`level` int(11) NOT NULL DEFAULT '0' COMMENT '类别,1、省份 2、市 3、区 4、县',
PRIMARY KEY (`id`),
UNIQUE KEY `UNQ_RID` (`rel_id`) USING BTREE,
KEY `IDX_PID` (`rel_id`)
) ENGINE=InnoDB AUTO_INCREMENT=55185 DEFAULT CHARSET=utf8 COMMENT='地区表';
3、43插入3条语句,44完全同步
INSERT INTO `test`.`info_area` (`id`, `name`, `rel_id`, `pid`, `level`) VALUES ('10000', '北京', '10000', '10000', '1');
INSERT INTO `test`.`info_area` (`id`, `name`, `rel_id`, `pid`, `level`) VALUES ('10002', '三环以内', '100001000110002', '10001', '3');
INSERT INTO `test`.`info_area` (`id`, `name`, `rel_id`, `pid`, `level`) VALUES ('10003', '三环到四环之间', '100001000110003', '10001', '3');
4、 43删除id=10001
delete from info_area where id=10001;
5、44上面插入10001
INSERT INTO `test`.`info_area` (`id`, `name`, `rel_id`, `pid`, `level`) VALUES ('10001', '朝阳区', '1000010001', '10000', '2');
6、43上面插入10001
INSERT INTO `test`.`info_area` (`id`, `name`, `rel_id`, `pid`, `level`) VALUES ('10001', '朝阳区', '1000010001', '10000', '2');
由于主从复制,44也会同步该条数据,但是44上面刚刚已经插入过id=10001,所以此时报错
MySQL [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.200.43
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 83009452
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 83009382
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Could not execute Write_rows event on table test.info_area; Duplicate entry '10001' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000007, end_log_pos 83009421
Retrieved_Gtid_Set: 0f869100-71d1-11e7-be5e-000c29f2e72e:1-14
Executed_Gtid_Set: 0f869100-71d1-11e7-be5e-000c29f2e72e:1-13,
22fd263e-71d1-11e7-be5e-000c29fffc35:1
Auto_Position: 1
7、解决gtid下1062错误
mysql> stop slave;
mysql> set GTID_NEXT='0f869100-71d1-11e7-be5e-000c29f2e72e:14';
mysql> begin;
mysql> commit;
mysql> set GTID_NEXT='AUTOMATIC';
mysql> start slave;
注:
传统方式
mysql> stop slave;
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n;
mysql> start slave;
8、恢复正常
MySQL [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.200.43
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 83009452
Relay_Log_File: mysql-relay-bin.000003
Relay_Log_Pos: 448
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 83009452
Relay_Log_Space: 83010163
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 0f869100-71d1-11e7-be5e-000c29f2e72e
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 0f869100-71d1-11e7-be5e-000c29f2e72e:1-14
Executed_Gtid_Set: 0f869100-71d1-11e7-be5e-000c29f2e72e:1-14,
22fd263e-71d1-11e7-be5e-000c29fffc35:1
Auto_Position: 1
1 row in set (0.00 sec)
mysql gitd 主从搭建_Yii2 优雅的 Active Record - SegmentFault 思否相关推荐
- mysql时间 gt_关于Mysql 5.6 TIMESTAMPDIFFgt;=和gt;的一个问题 - SegmentFault 思否
请问一下,为什么查询出来1那个地方的数据是大于0的,但是2那个地方必须得用>=才行,用>就没有数据了呢? 创建表:CREATE TABLE `contract` ( `id` int(11 ...
- mysql分表动态扩展_小星星 的动态 - SegmentFault 思否
DolphinDB支持动态加载外部插件,以扩展系统功能.插件用C++编写,需要编译成".so"或".dll"共享库文件.本文着重介绍开发插件的方法和注意事项,并 ...
- Sharding-jdbc教程:Mysql数据库主从搭建
点击上方"方志朋",选择"置顶公众号" 技术文章第一时间送达! 这是系列文章Sharding-jdbc文章的第一篇,本篇文章主要讲述如何搭建Mysql的主从.搭 ...
- php activerecord,Yii2 优雅的 Active Record
这篇文章我们来看看在 Yii2 之中的 Active Record,为啥要将 Active Record 单独出来说呢?因为个人认为这是 Yii(不管是 Yii1.1 还是 Yii2)最强大的一部分功 ...
- Mysql数据库主从搭建
主库服务器:192.168.1.100 从库服务器:192.168.1.101 在两台服务器上安装mysql, yum -y install mysql mysql-server mysql-deve ...
- mysql router docker_Docker镜像瘦身 - SegmentFault 思否
本文分享如何在docker环境,搭建Mysql Innodb Cluster集群. MySQL InnoDB Cluster为用户提供了完整的MySQL高可用性解决方案. 本文使用了以下组件: MyS ...
- jsp servlet mysql封装_html2canvas使用中的坑 - SegmentFault 思否
项目简介 本系统基于JSP+Servlet+Mysql 一个基于JSP+Servlet+Jdbc的个人日记本系统.涉及技术少,易于理解,适合JavaWeb初学者学习使用. 难度等级:入门 技术栈 编辑 ...
- mysql spj_解决Electron启动出现短暂的白屏 - SegmentFault 思否
实验表如下: t4 t5 子查询分类: 查询对象的关系上分类: 1.相关子查询 select * from t4 where t4.id4 = any ( select t5.id5 from t5 ...
- mysql查询总成绩高于240_Egret应用开发实践(02) MVC 模块化 - SegmentFault 思否
SQL经典练习题(mysql版) 本人自己做了一遍,感觉受益颇多,所以拿出来给大家分享下.其中,由于本人对sql函数部分掌握的不好,15-19题没做出来,是参考的原文.如果有错误或者有更好的sql语句 ...
最新文章
- SVN linux 服务器端配置
- 深度学习目标检测法进化史,看这一篇就够了
- PAT (Basic Level) Practice (中文)1006 换个格式输出整数 (15 分)
- php redis微信发红包,高阶篇二 使用Redis队列发送微信模版消息
- 机器学习与不确定性_机器学习求职中的不确定性
- JVM性能提升50%,聊一聊背后的秘密武器Alibaba Dragonwell
- 致我们终将逝去的39%“峰值性能”!
- 5 种编程语言可能注定失败!
- 2017-9-19Linux基础知识(2)
- 非常好用的354款Procreate新型笔刷
- 基于AT89S52单片机的汽车尾灯控制电路设计
- 什么云服务器可以挂虚拟鼠标,云服务器 模拟鼠标
- 希腊字母在Vim 中的输入方法
- [转贴]杨式太极拳八十五式通释—1—王志远
- .gitignore文件不生效
- AE PR模板基本图形预设素材包动态字幕文字标题排版动画预设效果
- 人工智能帮助千万用户完成「隐形征信」计算
- cisco 华三 对接_H3C交换机与Cisco交换机STP协议对接注意事项
- 文华财经指标安装使用步骤,开多开空成功率95%公式指标多空买卖点信号
- 数据科学 5.1 数据处理(概念)
热门文章
- CSR8675学习笔记:USB HID通信
- 软件测试条件组合覆盖三角形,软件测试三角形问题(覆盖测试)
- 健身管理软件,管理更高效更简单
- java lombok.getter_详解lombok @Getter @Setter 使用注意事项
- Creo二次开发:创建工程图,生成球标和明细表
- 阿里云 MaxCompute 行业级应用(优酷、斗鱼)及 MaxCompute SQL 调优
- qcc514x-qcc304x调试笔记-电量表
- [猿来小课]Python开发入门第三讲:Python的安装
- sfm眼睛带viewtarget制作
- 没想到你竟然是这样的全职高手 | 从文本挖掘聊起