autocommit 我修改的

如果启用自动提交模式,则每个SQL语句将自行形成单个事务。所以如果该语句没有返回错误,则MySQL会在每个SQL语句之后进行commit。启用了autocommit的会话可以通过以明确的START TRANSACTION、BEGIN、COMMIT、ROLLBACK语句来执行多语句事务。

ROLLBACK语句会取消当前事务所做的所有修改。 COMMIT和ROLLBACK都释放在当前事务中设置的所有InnoDB锁。



例子:
mysql> CREATE TABLE customer (a INT, b CHAR (20), INDEX (a));
Query OK, 0 rows affected (0.00 sec)
mysql> -- Do a transaction with autocommit turned on.
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO customer VALUES (10, 'Heikki');
Query OK, 1 row affected (0.00 sec)
mysql> COMMIT;
Query OK, 0 rows affected (0.00 sec)
mysql> -- Do another transaction with autocommit turned off.
mysql> SET autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO customer VALUES (15, 'John');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO customer VALUES (20, 'Paul');
Query OK, 1 row affected (0.00 sec)
mysql> DELETE FROM customer WHERE b = 'Heikki';
Query OK, 1 row affected (0.00 sec)
mysql> -- Now we undo those last 2 inserts and the delete.
mysql> ROLLBACK;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM customer;
+------+--------+
| a | b |
+------+--------+
| 10 | Heikki |
+------+--------+
1 row in set (0.00 sec)
mysql>
下一篇:锁定读

成为你想看到的世界变革力量

创建者:万乐荣
最后更新时间 : 2019年1月12日 16:3

评论