The Downside of MySQL Auto-reconnect
A few days ago I was doing some cleanup on a passive master database using the MySQL client. I didn’t want my commands to be replicated so I executed set sql_log_bin=0
in my session.
One of my queries dropped an unused schema that I knew was corrupt, so I wasn’t too surprised when the drop database
command crashed the MySQL server. After the crash, the server came back up quickly, and my client automatically reconnected, so it was safe to keep running queries right?
Wrong.
When the client reconnected I lost my session state, so sql_log_bin
reverted to 1, and any commands I ran from that point forward would be replicated, which I did not want.
This behavior makes sense, and it’s documented in the manual:
Automatic reconnection can be convenient because you need not implement your own reconnect code, but if a reconnection does occur, several aspects of the connection state are reset on the server side and your application will not know about it. The connection-related state is affected as follows:
- Any active transactions are rolled back and autocommit mode is reset.
- All table locks are released.
- All TEMPORARY tables are closed (and dropped).
- Session variables are reinitialized to the values of the corresponding variables. This also affects variables that are set implicitly by statements such as SET NAMES.
- User variable settings are lost.
- Prepared statements are released.
- HANDLER variables are closed.
- The value of LAST_INSERT_ID() is reset to 0.
- Locks acquired with GET_LOCK() are released.
But it’s easy to overlook such details when working with automatic features like MySQL client auto-reconnect. In this specific case I didn’t execute any other commands in the reconnected session so I didn’t inadvertantly replicate anything, but this incident served as a good reminder to be vigilant about my session state when using the MySQL client.
Here’s a snippet from my session to show the value of sql_log_bin
before and after the crash:
1 |
|
https://mechanics.flite.com/blog/2013/05/03/the-downside-of-mysql-auto-reconnect/
The Downside of MySQL Auto-reconnect的更多相关文章
- mysql AUTO INCREMENT字段 语法
mysql AUTO INCREMENT字段 语法 作用:在新记录插入表中时生成一个唯一的数字 说明:我们通常希望在每次插入新记录时,自动地创建主键字段的值.我们可以在表中创建一个 auto-incr ...
- mysql auto reset
参数说明: •相关参数说明: •dataSource: 要连接的 datasource (通常我们不会定义在 server.xml) defaultAutoCommit: 对于事务是否 autoCom ...
- MySQL(Percona Server) 5.6 主从复制
MySQL(Percona Server) 5.6.15 主库:192.168.2.21 从库:192.168.2.22 例如我们同步的数据库为:test. 如果需要同步多个数据库下面会有说明. My ...
- 使用 xtrabackup 进行MySQL数据库物理备份
0. xtrabackup的功能 能实现的功能: 非阻塞备份innodb等事务引擎数据库. 备份myisam表会阻塞(需要锁). 支持全备.增量备份.压缩备份. 快速增量备份(xtradb,原理类似于 ...
- centos升级mysql至5.7
1.备份原数据库 [root@www ~] #mysqldump -u root –p -E –all-database > /home/db-backup.sql 加-E是因为mysqldum ...
- mysql 双机热备注意事项
上一篇文章已经介绍过 主从复制, 本文对主从复制只是简单描述,如对主从复制不清楚的,可以先看上一篇文章 主从复制 一:介绍 mysql版本:5.7.20 第一个主服服务器ip:192. ...
- .NET Core+MySql+Nginx 容器化部署
.NET Core容器化@Docker .NET Core容器化之多容器应用部署@Docker-Compose .NET Core+MySql+Nginx 容器化部署 GitHub-Demo:Dock ...
- Mysql主从复制_模式之日志点复制
MySQL数据复制的原理 MySQL复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新.删除等等).因此,要进行复制,必须在主服务器上启用二进制日志. 每个从服务器从主服务器接收主服务器已经记 ...
- 安装Percona版本的MySQL主从复制
准备两台虚拟机,按顺序执行1.1节的公共部分 1.1 首先安装 cmake # yum –y install cmake //也需要安装gcc-c++,openssl openssl-deve ...
随机推荐
- 分布式理论(五)—— 一致性算法 Paxos
前言 Paxos 算法如同我们标题大图:世界上只有一种一致性算法,就是 Paxos.出自一位 google 大神之口. 同时,Paxos 也是出名的晦涩难懂,推理过程极其复杂.楼主在尝试理解 Paxo ...
- .1-浅析webpack源码之webpack.cmd
此系列随时可能断更,毕竟我是解释型源码分析…… tips:本系列源码版本为3.10.0 尝试看过Spring的源码,有点烧脑,所以还是重回JS吧! 在配置完环境变量后,可以通过webpack指令进行打 ...
- element-ui2源码修改小问题
最近element-ui升级到2了,添加了不少功能,可喜可贺,可喜可贺! 然而,产品的需求依然那么刁钻,上传与删除图片还是要去改源码,为了同时用新的ele,决定在2中改源码 然而,遇到问题了. 一开始 ...
- JUC源码阅读参考文章
(飞哥)http://brokendreams.iteye.com/blog/2252081 (熊猫)http://blog.csdn.net/xiaoxufox/article/details/51 ...
- 啰里吧嗦CountDownLatch
java.util.concurrent Class CountDownLatch 目录 CountDownLatch 是什么 CountDownLatch是一个同步工具类,它允许一个或多个线程一直等 ...
- 步步深入MySQL:架构->查询执行流程->SQL解析顺序!
一.前言 一直是想知道一条SQL语句是怎么被执行的,它执行的顺序是怎样的,然后查看总结各方资料,就有了下面这一篇博文了. 本文将从MySQL总体架构--->查询执行流程--->语句执行顺序 ...
- java基础进阶二:HashMap实现原理分析
HashMap实现原理分析 1. HashMap的数据结构 数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端. 数组 数组存储区间是连续的,占用内存严重,故空间复杂的很大.但数组的二 ...
- Three.js开发指南---创建,加载高级网格和几何体(第八章)
本章的主要内容: 一, 通过Three.js自带的功能来组合和合并已有的几何体,创建出新的几何体 二, 从外部资源中加载网格和几何体 1 前面的章节中,我们学习到,一个几何体创建的网格,想使用多个材质 ...
- python中matplotlib.pyplot中cm的属性
https://matplotlib.org/gallery/color/colormap_reference.html
- ES6--JavaScript的第六个版本
一.新的变量声明方式 let/cons 与var不同,新的变量声明方式带来了一些不一样的特性,其中最重要的两个特性就是提供了块级作用域与不再具备变量提升. 若是对变量提升不怎么了解的话可以去参考我的其 ...