支持事务处理的表必须是BDB类型
SET AUTOCOMMIT=0
BEGIN;
UPDATE table1 SET field1='aaa' WHERE type=1;
UPDATE table2 SET field2='bbb' WHERE type=1;
COMMIT;//或ROLLBACK;
SET AUTOCOMMIT=0
BEGIN;
UPDATE table1 SET field1='aaa' WHERE type=1;
UPDATE table2 SET field2='bbb' WHERE type=1;
COMMIT;//或ROLLBACK;
使用方法同上
我在MySQL中建立了个表tmp
tmp的表结构是这样的:
mysql> describe tmp;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | | PRI | 0 | |
| data | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)然后我做了如下的操作(最开始表格中没有记录)
mysql> select * from tmp;
Empty set (0.00 sec)mysql> begin;
Query OK, 0 rows affected (0.00 sec)mysql> insert into tmp(id,data) values(1,1);
Query OK, 1 row affected (0.00 sec)mysql> insert into tmp(id,data) values(1,1);
ERROR 1062: Duplicate entry '1' for key 1
mysql> commit;
Query OK, 0 rows affected (0.00 sec)那因为关键字的原因,这个事务应该不会插入任何纪录,tmp表应该还是空的
可是
mysql> select * from tmp;
+----+------+
| id | data |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.00 sec)
这是为什么呀?!?!
mysql> rollback;
ERROR 1196: Warning: Some non-transactional changed tables couldn't be rolled back
windows下把mysqld-max.exe注册成服务
mysqld-max.exe -install
然后启动服务之后建表类型为innodb(mysql官方 推荐).
操作步骤如同binscut所描述
SET AUTOCOMMIT=0
BEGIN;
UPDATE table1 SET field1='aaa' WHERE type=1;
UPDATE table2 SET field2='bbb' WHERE type=1;
COMMIT;//或ROLLBACK;注:需mysql-max版本
建议你用show table status 看看自己的tmp表是什么类型