MySQLStudy之--MySQL关闭自动commit(autocommit)
MySQL Study之--MySQL关闭自动commit(autocommit) 对于mysql来讲,在事务处理时,默认是在动提交的(autocommit),以下方法可以自动关闭autocommit; 案例分析: 1、在mysql登录环境下修改 [root@mysql2 soft]# mysql -u root -p Enter password: Welcome
MySQL Study之--MySQL关闭自动commit(autocommit)
对于mysql来讲,在事务处理时,默认是在动提交的(autocommit),以下方法可以自动关闭autocommit;
案例分析:
1、在mysql登录环境下修改
[root@mysql2 soft]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
mysql> select version();
+-------------+
| version() |
+-------------+
| 5.6.25-73.1 |
+-------------+
1 row in set (0.00 sec)
mysql> show variables like '%autocommit%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON | ;;默认autocommit是开启的
+---------------+-------+
1 row in set (0.03 sec)
在当前session关闭autocommit:
mysql> set @@session.autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%autocommit%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF |
+---------------+-------+
1 row in set (0.00 sec)
在global级别关闭autocommit:
mysql> set @@global.autocommit=0;
Query OK, 0 rows affected (0.01 sec)
创建普通用户:
mysql> create user tom identified by 'tom';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on prod.* to 'tom'@'localhost' identified by 'tom';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
普通用户登录:
[root@mysql2 ~]# mysql -u tom -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
ERROR 1044 (42000): Access denied for user 'tom'@'localhost' to database 'mysql'
mysql> use prod;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> show variables like '%commit%';
+-------------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------------+-------+
| autocommit | OFF |
| binlog_order_commits | ON |
| innodb_api_bk_commit_interval | 5 |
| innodb_commit_concurrency | 0 |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_use_global_flush_log_at_trx_commit | ON |
+-------------------------------------------+-------+
6 rows in set (0.00 sec)
创建测试表:
mysql> create table t1(id int,name varchar(10));
Query OK, 0 rows affected (0.15 sec)
mysql> insert into t1 values (10,'tom');
Query OK, 1 row affected (0.00 sec)
mysql> select * from t1;
+------+------+
| id | name |
+------+------+
| 10 | tom
|
+------+------+
1 row in set (0.00 sec)
事务回滚:
mysql> rollback;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from t1;
Empty set (0.00 sec)
2、在mysql service重启后
mysql server 重启后:
[root@mysql2 ~]# service mysql stop
Shutting down MySQL (Percona Server)....[ OK ]
[root@mysql2 ~]# service mysql start
Starting MySQL (Percona Server).....[ OK ]
[root@mysql2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%commit%';
+-------------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------------+-------+
| autocommit | ON | ;;autocommit仍然是开启状态
+-------------------------------------------+-------+
6 rows in set (0.01 sec)
编辑/etc/my.cnf文件:
[root@mysql2 ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
init_connect='set autocommit=0' ;;用户登录时,关闭autocommit
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
explicit_defaults_for_timestamp=true
innodb_buffer_pool_size = 128M
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
用户登录查看:
[root@mysql2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%commit%';
+-------------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------------+-------+
| autocommit | ON | ;;root用户不受影响(为安全起见)
mysql> system mysql -u tom -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%commit%';
+-------------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------------+-------+
| autocommit | OFF | ;;普通用户,autocommit已被关闭
+-------------------------------------------+-------+

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

新浪新聞軟體內提供的新聞頭條資訊非常多,基本上都是官方平台推送的,每一篇新聞文章內容都是擁有真實性的,上下滑動一鍵搜尋翻閱,整體的閱讀氛圍更加舒適。輸入手機號碼在線上登錄,不同領域的新聞頻道都是開放的,二十四小時更新都是不重複的,國內外、地方時事新聞都不會少的,上下滑動選擇一鍵翻閱,新聞內容都是大家感興趣的,還能關閉新聞速遞功能,這樣也不會被影響到,任何時候都可以打開一覽,海量熱門的新聞頭條新鮮事搶先看,現在小編在線詳細為新浪新聞用戶們帶來關閉速遞功能的操作步驟。 找到新浪新聞進入,點選右下角

抖音是一款備受歡迎的短影片社群平台,讓使用者可以簡單地記錄生活、分享快樂。私訊功能在抖音中扮演著重要的角色,是使用者互動的主要方式之一。有時候,用戶可能會碰到對方關閉了私訊模式,導致無法傳送訊息的情況。一、抖音私訊對方關閉了私訊模式怎麼開啟? 1.確認對方是否開啟了隱私設置首先,我們應該確認對方是否啟用了隱私設置,可能已經限制了私訊的接收。如果他們設定了僅允許熟人私信,我們可以嘗試透過其他途徑聯繫他們,例如透過共同的朋友或在社群媒體平台上互動。 2.發送好友申請如果對方並未開啟隱私設置,那麼我們

在Windows11作業系統中,安全中心是一個重要的功能,它可幫助使用者監控系統安全狀態、防禦惡意軟體和保護個人隱私。然而,有時使用者可能需要暫時關閉安全中心,例如在安裝某些軟體或進行系統調優時。本文將詳細介紹Windows11安全中心的關閉方法,協助您正確且安全地作業系統。 1.如何關閉Windows11安全中心在Windows11中,關閉安全中心並不

快手是一款很卓越的影片播放器,快手中的免密支付功能小夥伴們都非常熟悉,在日常生活中可以給我們很大的幫助,尤其是在平台中購買自己需要的商品時可以更好的去支付,我們現在要去取消掉該如何操作呢?怎麼樣才能真正有效取消掉免密支付功能?免密支付取消的方法非常簡單,具體的操作方法已經整理好了,讓我們一起到本站本站中來看整篇攻略吧,希望能夠幫助大家。快手關閉免機密支付方式教學 1、開啟快手app,點選左上角的三條橫線。 2、點選快手小店。 3、在上面的選項列中,找到免密付款並點擊進去。 4、點擊支

360瀏覽器推薦的廣告如何關閉?相信很多的用戶都在使用360瀏覽器,不過這款瀏覽器有時候會彈出廣告,這就使得很多的用戶們都十分的苦惱,下面就讓本站來為用戶們來仔細的介紹一下如何關閉電腦360瀏覽器推薦的廣告吧。 如何關機360瀏覽器推薦的廣告? 方法一: 1、開啟360安全瀏覽器。 2、找到右上角「三橫槓」標誌,點選【設定】。 3、在彈出的介面左側工作列中找到【實驗室】,勾選【啟用「360熱點資訊」功能】即可。 方法二: 1、先雙擊

Windows作業系統作為全球用戶數量最龐大的作業系統之一,一直以來備受用戶青睞。然而,在使用Windows系統時,使用者可能會遇到許多安全隱患,例如病毒攻擊、惡意軟體等威脅。為了強化系統安全,Windows系統內建了許多安全保護機制,其中之一就是Windows安全中心的即時保護功能。今天,我們將會詳細介紹Windows安全中心即時保護的關閉方法。首先,讓我們

1.在手機設定中點選聲音與震動。 2、點選杜比全景音。 3.將杜比全景聲後方的開關關閉即可。

Windows11是微軟公司最新推出的作業系統版本,相較於先前的版本,Windows11對系統安全性進行了更嚴格的管理和監控,其中一個重要的功能就是安全中心。安全中心可以幫助使用者管理和監控系統的安全狀態,確保系統不受惡意軟體和其他安全威脅的侵害。雖然安全中心對於保護系統安全很重要,但有時使用者可能會因為個人需求或其他原因希望關閉安全中心。本文將介紹如何在W
