mysql禁用autocommit

来源:互联网 发布:平刷王时时彩软件怎样 编辑:程序博客网 时间:2024/06/05 19:03
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.

整理自网络

0 0
原创粉丝点击