mysql禁用autocommit

mysql默认开启auto commit,我们可以通过系统变量控制来动态控制session级别autocommit

(set autocommit = 0|1),

如何从全局禁用autocommit呢,也许有时候我们不想让mysql自动提交。

mysql有一个Cmd-Line&Option file&System Var可以帮助我们实现这样的功能,它就是init_connect。

这个参数用来定义每个session建立时自动执行的query。

A string to be executed by the server for each client that connects. The string consists of one or more SQL statements. To specify multiple statements, separate them by semicolon characters.A string to be executed by the server for each client that connects. The string consists of one or more SQL statements. To specify multiple statements, separate them by semicolon characters.

利用这个变量,可以通过如下方式禁用autocommit:

way1:mysql>SET GLOBAL init_connect=’SET autocommit=0′;

way2:在初始化参数文件中设置

[mysqld]

init_connect=’SET autocommit=0′

way3:

启动mysql时带上命令行参数–init_connect=’SET autocommit=0′

当然这个参数的设置对拥有super权限的用户是无效的,具体说明

Note that the content of init_connect is not executed for users that have the SUPER privilege. This is done so that an erroneous value for init_connect does not prevent all clients from connecting. For example, the value might contain a statement that has a syntax error, thus causing client connections to fail. Not executing init_connect for users that have the SUPER privilege enables them to open a connection and fix the init_connect value.

整理自网络

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值