mysql> SHOW VARIABLES LIKE 'autocommit'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | autocommit | ON | +---------------+-------+ 1 row in set, 1 warning (0.04 sec)结果显示,autocommit 的值是 ON,表示系统开启自动提交模式。
SET autocommit = 0|1|ON|OFF;
对取值的说明:mysql> SET autocommit = 0; ; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM mybank.bank; +--------------+--------------+ | customerName | currentMoney | +--------------+--------------+ | 张三 | 1000.00 | | 李四 | 1.00 | +--------------+--------------+ 2 rows in set (0.00 sec) mysql> UPDATE bank SET currentMoney = currentMoney-500 WHERE customerName='张三' ; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> UPDATE bank SET currentMoney = currentMoney+500 WHERE customerName='李四'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM mybank.bank; +--------------+--------------+ | customerName | currentMoney | +--------------+--------------+ | 张三 | 1000.00 | | 李四 | 1.00 | +--------------+--------------+ 2 rows in set (0.00 sec)结果显示,张三和李四的余额是事务执行前的数据。
mysql> COMMIT; Query OK, 0 rows affected (0.07 sec) mysql> SELECT * FROM mybank.bank; +--------------+--------------+ | customerName | currentMoney | +--------------+--------------+ | 张三 | 500.00 | | 李四 | 501.00 | +--------------+--------------+ 2 rows in set (0.00 sec)结果显示,bank 数据表的数据更新成功。
本文链接:http://task.lmcjl.com/news/15001.html