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 ...
随机推荐
- 【转载】配置文件报错:不允许有匹配 [xX][mM][lL] 的处理指令目标
今天编写代码的时候,不小心给一个xml文件的首行加了一行空格,导致了启动报了如题类似的错误,查到一篇文章,顺藤摸瓜发现了这个失误,文章转载如下: 框架整合 的时候,XML 配置文件大多数情况是从另一个 ...
- 防止 IE 自动跳兼容模式
在HTML <head> 中增加如下: <meta http-equiv="x-ua-compatible" content="IE=edge" ...
- Docker 使用官方镜像
Docker 使用官方镜像 如何使用官方镜像 Docker 中国官方镜像加速可通过 registry.docker-cn.com 访问.目前该镜像库只包含流行的公有镜像,而私有镜像仍需要从美国镜像库中 ...
- ConcurrentHashMap 源码阅读小结
前言 每一次总结都意味着重新开始,同时也是为了更好的开始.ConcurrentHashMap 一直是我心中的痛.虽然不敢说完全读懂了,但也看了几个重要的方法,有不少我觉得比较重要的知识点. 然后呢,放 ...
- 了解java虚拟机—CMS回收器(8)
CMS(Concurrent Mark Sweep)回收器 它使用的是标记清除算法,同时又是一个使用多线程并行回收的垃圾回收器. CMS主要工作步骤 CMS工作时主要步骤有初始标记.并发标记.预清理. ...
- Java - HashCode源码解析
Java提高篇(二六)-----hashCode hashCode的作用 要想了解一个方法的内在原理,我们首先需要明白它是干什么的,也就是这个方法的作用.在讲解数组时(java提高篇(十八)----- ...
- hadoop_完全分布式配置
注:此文章所写内容完全在虚拟机配置,系统:centos,jdk和hadoop已经安装完成所配集群包括hadoop01,hadoop02,hadoop03,hadoop04四台,ip分别为:192.16 ...
- php面向对象精要(1)
1.静态属性与方法 每一个类的实例拥有自己的属性和方法,每一个类也可以包含静态属性,静态属性不属于类的任何实例,可以把静态属性理解成存储在类中的全局变量,可以在任何地方通过类名引用静态属性. < ...
- 查看linux 内存
1.vmstat vmstat命令显示实时的和平均的统计,覆盖CPU.内存.I/O等内容.例如内存情况,不仅显示物理内存,也统计虚拟内存. $ vmstat -s 2.top top命令提供了实时的运 ...
- JSON 解析与封装
作者QQ:1095737364 QQ群:123300273 欢迎加入! 1.解析: var str = '{"name":"huangxiaojian&qu ...