Heim > Datenbank > MySQL-Tutorial > Hauptteil

mysql设立autocommit关闭

WBOY
Freigeben: 2016-06-07 16:25:21
Original
1212 Leute haben es durchsucht

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
Nach dem Login kopieren

?

但是,这个参数的设置对拥有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>
Nach dem Login kopieren
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!