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:
|
|
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 ...
随机推荐
- epoll 触发模式
Edge Triggered (ET):边缘触发只有数据到来,才触发,不管缓存区中是否还有数据.Level Triggered (LT):水平触发只要有数据都会触发. LT(level trigger ...
- 33-hadoop-cdh搭建coudemanager安装
http://www.aboutyun.com/thread-9219-1-1.html 非常强大的博客 ! ! ! 1, cdh简介 CDH (Cloudera’s Distribution, i ...
- 复刻smartbits的国产网络测试工具minismb功能特点-如何加载、发送PCAP数据包
复刻smartbits的网络性能测试工具minismb,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此以太网测试工具测试任何ip网络设备的端口吞吐率,带宽,并发 ...
- 【跟着开涛学Shiro】(一)Shiro简介
声明:本部分内容均转自于张老师的博客,因为本人很喜欢他的博客,所以一直在学习,转载仅是记录和分享,若也有喜欢的人的话,可以去他的博客首页看:http://jinnianshilongnian.itey ...
- Spring事务传播属性介绍(一).required 和 reuqires_new
Mandatory.Never.Not_Support传播属性分析传送门:https://www.cnblogs.com/lvbinbin2yujie/p/10260030.html Nested传播 ...
- postcss
一.简介 PostCSS 本身是一个功能比较单一的工具.它提供了一种方式用 JavaScript 代码来处理 CSS.它负责把 CSS 代码解析成抽象语法树结构(Abstract Syntax Tre ...
- C#操作MongoDB入门
1.MongoDB安装及配置 (1)下载: mongodb官网 https://www.mongodb.com/download-center 进入官网下载页,你会发现版本都是windo ...
- Maven包查询库
第一个: http://search.maven.org/ 第二个: http://mvnrepository.com/artifact/aspectj/aspectjweaver
- Java对MySQL数据库进行连接、查询和修改(转)
Java对MySQL数据库进行连接.查询和修改 0. 一般过程: (1) 调用Class.forName()方法加载驱动程序. (2) 调用DriverManager对象的getConnection( ...
- HDU1054(KB10-H 最小顶点覆盖)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...