MySQL 全局禁用autocommit

mysql默认开启auto commit,我们可以通过系统变量控制来动态控制session级别autocommit,如何从全局禁用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.

参考:http://dev.mysql.com/doc/refman/ … sysvar_init_connect

摘自『http://www.itpub.net/thread-1205953-1-1.html』

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

粤ICP备15062915号-1