MySQL Study之--MySQL关闭自动commit(autocommit)的方法

2026-03-08 05:45 栏目: 常见问题 查看( )

对于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)

MySQL Study之--MySQL关闭自动commit(autocommit)的方法第一张图

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  ]

MySQL Study之--MySQL关闭自动commit(autocommit)的方法第二张图

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

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流

郑重申明:某某网络以外的任何单位或个人,不得使用该案例作为工作成功展示!