对于mysql来讲,在事务处理时,默认是在动提交的(autocommit),以下方法可以自动关闭autocommit;
案例分析:
1、在mysql登录环境下修改
[chinastor.com-root@mysql2 soft]# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or g.
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
affiliates. Other names may be trademarks of their respective
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
+--------------------+
+--------------------+
| mysql |
| test |
4 rows in set (0.02 sec)
+-------------+
+-------------+
+-------------+
+---------------+-------+
+---------------+-------+
+---------------+-------+
mysql> set @@session.autocommit=0;
+---------------+-------+
+---------------+-------+
+---------------+-------+
mysql> set @@global.autocommit=0;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Enter password:
Your MySQL connection id is 6
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Oracle is a registered trademark of Oracle Corporation and/or its
owners.
ERROR 1044 (42000): Access denied for user 'tom'@'localhost' to database 'mysql'
Database changed
Empty set (0.00 sec)
+-------------------------------------------+-------+
+-------------------------------------------+-------+
| binlog_order_commits | ON |
| innodb_commit_concurrency | 0 |
| innodb_use_global_flush_log_at_trx_commit | ON |
6 rows in set (0.00 sec)
Query OK, 0 rows affected (0.15 sec)
Query OK, 1 row affected (0.00 sec)
+------+------+
+------+------+
|
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.02 sec)
Empty set (0.00 sec)
mysql server 重启后:
Shutting down MySQL (Percona Server)....[ OK ]
Starting MySQL (Percona Server).....[ OK ]
Enter password:
Your MySQL connection id is 1
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Oracle is a registered trademark of Oracle Corporation and/or its
owners.
+-------------------------------------------+-------+
+-------------------------------------------+-------+
+-------------------------------------------+-------+
[mysqld]
[mysqld_safe]
Welcome to the MySQL monitor. Commands end with ; or g.
Server version: 5.6.25-73.1 Percona Server (GPL), Release 73.1, Revision 07b797f
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
affiliates. Other names may be trademarks of their respective
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
+-------------------------------------------+-------+
+-------------------------------------------+-------+
Enter password:
Your MySQL connection id is 2
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Oracle is a registered trademark of Oracle Corporation and/or its
owners.
+-------------------------------------------+-------+
+-------------------------------------------+-------+
+-------------------------------------------+-------+
该篇文章出自 “天涯客的blog” 博客,请务必保留此出处http://tiany.blog.51cto.com/513694/1683722