[英]How to turn off autocommit in mariadb?
I am using mariasql and the mysql workbench IDE for mariasql, but I am not able to disable the autocommit mode.我正在使用 mariasql 和用于 mariasql 的 mysql 工作台 IDE,但我无法禁用自动提交模式。 How do I turn off the autocommit?
如何关闭自动提交?
I use XAMPP-VM with MariaDB with InnoDB.我将 XAMPP-VM 与 MariaDB 与 InnoDB 一起使用。 Couldn't manage to disable autocommit with my.conf, however, I edited mysql.server file (for XAMPP-VM it's in /opt/lampp/bin folder) and added this parameter to startup
无法使用 my.conf 禁用自动提交,但是,我编辑了 mysql.server 文件(对于 XAMPP-VM,它位于 /opt/lampp/bin 文件夹中)并将此参数添加到启动
--autocommit=0
So at the end, it looks like this所以最后,它看起来像这样
...
case "$mode" in
'start')
# Start daemon
...
$bindir/mysqld_safe --autocommit=0 --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
...
and it did the trick.它做到了。 You can check it with this after stop-start (restart won't apply the change as that goes on a different path in the switch)
您可以在停止启动后使用此检查它(重新启动不会应用更改,因为它在交换机中的不同路径上进行)
select *
from information_schema.global_variables
where variable_name = 'AUTOCOMMIT';
The other side of the coin is if you upgrade then you need to repeat this.硬币的另一面是,如果您升级,则需要重复此操作。
Hope, you can adopt this solution / gives you some idea how to do it!希望,您可以采用此解决方案/让您知道如何去做!
You can set autocommit to false for the session :您可以将会话的自动提交设置为 false:
SET autocommit = 0;
https://mariadb.com/kb/en/mariadb/server-system-variables/#autocommit https://mariadb.com/kb/en/mariadb/server-system-variables/#autocommit
I consider it a mistake to turn off autocommit
.我认为关闭
autocommit
是一个错误。
There are 3 ways for dealing with autocommit:有3种处理自动提交的方法:
autocommit=1
-- all statements are immediately committed. autocommit=1
-- 所有语句都立即提交。 This is usually fine for casual usage.这通常适合休闲使用。
BEGIN
... COMMIT
-- where you explicitly bracket a set of SQL statements. BEGIN
... COMMIT
-- 在其中显式括起一组 SQL 语句。 By having the BEGIN
, you are reminded that a COMMIT
will be needed.有了
BEGIN
,你会被提醒需要一个COMMIT
。
autocommit=0
... COMMIT
-- I see this as error prone. autocommit=0
... COMMIT
-- 我认为这很容易出错。 You default autocommit to 0, but then forget to issue COMMIT
.您默认自动提交为 0,但随后忘记发出
COMMIT
。 Then you wonder why your INSERTs
disappeared.然后你想知道为什么你的
INSERTs
消失了。
The only way I found is to add --autocommit=0
to the startup command of the daemon.我发现的唯一方法是将
--autocommit=0
添加到守护程序的启动命令中。
Environment:环境:
$ mariadb --version
mariadb Ver 15.1 Distrib 10.5.6-MariaDB, for Linux (x86_64) using readline 5.1
$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Oracle Linux Server 7.9"
One-line command:一行命令:
NOTE: You still need to add --autocommit=0
manually.注意:您仍然需要手动添加
--autocommit=0
。
$ vim /usr/lib/systemd/system/mariadb.service && systemctl daemon-reload && systemctl restart mariadb && mariadb -u root -e "show variables like '%autocommit%'"
Step-by-step commands:分步命令:
$ vim /usr/lib/systemd/system/mariadb.service
--autocommit=0
to ExecStart
(for me it was in #92)--autocommit=0
添加到ExecStart
(对我来说它在 #92 中)ExecStart=/usr/sbin/mariadbd --autocommit=0 $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
$ systemctl daemon-reload
$ systemctl restart mariadb
autocommit
variableautocommit
变量的状态$ mariadb -u root -e "show variables like '%autocommit%'"
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| autocommit | OFF |
...
+------------------------+-------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.