I am using mariasql and the mysql workbench IDE for mariasql, but I am not able to disable the autocommit mode. How do I turn off the autocommit?
I use XAMPP-VM with MariaDB with 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
--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 :
SET autocommit = 0;
https://mariadb.com/kb/en/mariadb/server-system-variables/#autocommit
I consider it a mistake to turn off autocommit
.
There are 3 ways for dealing with autocommit:
autocommit=1
-- all statements are immediately committed. This is usually fine for casual usage.
BEGIN
... COMMIT
-- where you explicitly bracket a set of SQL statements. By having the BEGIN
, you are reminded that a COMMIT
will be needed.
autocommit=0
... COMMIT
-- I see this as error prone. You default autocommit to 0, but then forget to issue COMMIT
. Then you wonder why your INSERTs
disappeared.
The only way I found is to add --autocommit=0
to the startup command of the daemon.
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.
$ 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)ExecStart=/usr/sbin/mariadbd --autocommit=0 $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
$ systemctl daemon-reload
$ systemctl restart mariadb
autocommit
variable$ mariadb -u root -e "show variables like '%autocommit%'"
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| autocommit | OFF |
...
+------------------------+-------+
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.