MySQL5.7的事务控制语句的介绍

START TRANSACTION 或 BEGIN 语句开始一个事务

COMMIT 语句提交事务,使得数据的更改永久生效

ROLLBACK 语句回滚事务,取消对数据的更改

SET autocommit 语句禁止或启用当前会话默认的事务自动提交功能

--例子
MySQL> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @A:=SUM(deptno) FROM test;
+-----------------+
| @A:=SUM(deptno) |
+-----------------+
|             150 |
+-----------------+
1 row in set (0.00 sec)
mysql> UPDATE test SET deptno=@A WHERE deptno=10;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.01 sec)

--关闭当前会话事务的自动提交功能
mysql> SET autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%commit%';
+--------------------------------+-------+
| Variable_name                  | Value |
+--------------------------------+-------+
| autocommit                     | OFF   |
| innodb_commit_concurrency      | 0     |
| innodb_flush_log_at_trx_commit | 1     |
+--------------------------------+-------+
3 rows in set (0.00 sec)
网站栏目:MySQL5.7的事务控制语句的介绍
标题路径:http://ybzwz.com/article/pposic.html