mysql设置autocommit_mysql设置autocommit关闭

mysql默认开启auto commit,可以,通过这几个sql查看:

select @@autocommit;

SHOW VARIABLES LIKE '%AUTOCOMMIT%';

SHOW GLOBAL STATUS LIKE '%AUTOCOMMIT%';

我们可以通过系统变量控制来动态控制session级别autocommit

(set autocommit = 0|1),session级别的用处不大,全局禁用才好。

如何从全局禁用autocommit呢,大多数时候我们不想让mysql自动提交,用程序代码来控制,比如spring的声明式事务。

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

一个比较好用的设置方法是在mysql的初始化文件my.int里加多一行设置。如我的my.int文件路径是:D:\Program Files\MySQL\MySQL Server 5.1\my.int,打开这个文件,在[mysqld]下面加多一行:init_connect=’SET autocommit=0′,如:

[mysqld]

#这个对拥有root权限的用户无效

init_connect='SET autocommit=0'

# The TCP/IP Port the MySQL Server will listen on

port=3306

但是,这个参数的设置对拥有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.

估计是mysql的一个bug.

另外:mysql默认的存储引擎是InnoDB,支持事务操作。

一般情况下,mysql会默认提供多种存储引擎,你可以通过下面的查看:

看你的mysql现在已提供什么存储引擎:

mysql> show engines;

看你的mysql当前默认的存储引擎:

mysql> show variables like '%storage_engine%';

你要看某个表用了什么引擎(在显示结果里参数engine后面的就表示该表当前用的存储引擎):

mysql> show create table 表名;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值