Home > Database > Mysql Tutorial > body text

mysql设立autocommit关闭

WBOY
Release: 2016-06-07 16:25:21
Original
1211 people have browsed it

mysql设置autocommit关闭 mysql默认开启auto commit,可以,通过这几个sql查看: select @@autocommit; SHOW VARIABLES LIKE '%AUTOCOMMIT%'; SHOW GLOBAL STATUS LIKE '%AUTOCOMMIT%'; ? 我们可以通过系统变量控制来动态控制session级别autocommit (set auto

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
Copy after login

?

但是,这个参数的设置对拥有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,支持事务操作。

?

<span class="ask-title" ><span class="ask-title" >一般情况下,mysql会默认提供多种<span class="ask-title" >存储引擎</span>,你可以通过下面的查看:</span>

<span class="ask-title" >看你的mysql现在已提供什么<span class="ask-title" >存储引擎</span>:</span>
<span class="ask-title" >mysql> show engines;</span>

<span class="ask-title" >看你的mysql当前默认的<span class="ask-title" >存储引擎</span>:</span>
<span class="ask-title" >mysql> show variables like '%storage_engine%';</span>

<span class="ask-title" >你要看某个表用了什么引擎(在显示结果里参数engine后面的就表示该表当前用的存储引擎):</span>
<span class="ask-title" >mysql> show create table 表名;</span></span>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!