Mysql 关闭自动提交

来源:互联网 发布:太阳能充电 知乎 编辑:程序博客网 时间:2024/05/29 03:03
回话级关闭自动提交mysql> set autocommit=off;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)回话1:mysql> desc t1    -> ;+-------+---------+------+-----+---------+-------+| Field | Type    | Null | Key | Default | Extra |+-------+---------+------+-----+---------+-------+| id    | int(11) | YES  |     | NULL    |       |+-------+---------+------+-----+---------+-------+1 row in set (0.00 sec)mysql> select * from t1;+------+| id   |+------+|    1 |+------+1 row in set (0.00 sec)mysql> insert into t1 values(2);Query OK, 1 row affected (0.01 sec)mysql> select * from t1;+------+| id   |+------+|    1 ||    2 |+------+2 rows in set (0.00 sec)回话2:mysql> select * from t1;+------+| id   |+------+|    1 |+------+1 row in set (0.00 sec)可以看到此时关闭自动提交已经生效mysql> select * from t1;+------+| id   |+------+|    1 ||    2 |+------+2 rows in set (0.00 sec)mysql> rollback;Query OK, 0 rows affected (0.06 sec)mysql>  select * from t1;+------+| id   |+------+|    1 |+------+1 row in set (0.00 sec)

0 0
原创粉丝点击