Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4179634
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2007-12-19 10:40:44

举个例子吧。自己实验了一下。
对MYSQL的innodb 和 ndb 引擎对事务的处理
对于NDB
mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into foo values(1);
Query OK, 1 row affected (0.01 sec)

mysql> insert into foo values(1);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> commit;
ERROR 1296 (HY000): Got error 4350 'Transaction already aborted' from NDBCLUSTER
mysql> show errors;
+-------+------+--------------------------------------------------------------+
| Level | Code | Message                                                      |
+-------+------+--------------------------------------------------------------+
| Error | 1296 | Got error 4350 'Transaction already aborted' from NDB        |
| Error | 1296 | Got error 4350 'Transaction already aborted' from NDBCLUSTER |
| Error | 1180 | Got error 4350 during COMMIT                                 |
+-------+------+--------------------------------------------------------------+
3 rows in set (0.00 sec)

mysql> select * from foo;
Empty set (0.00 sec)
对于INNODB
mysql> create table foo2 (i int not null primary key) engine innodb;

Query OK, 0 rows affected (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into foo2 values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into foo2 values(1);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from foo2;
+---+
| i |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
NDB遇到错误就终止了,回滚到最初的状态。
而INNODB遇到错误还是继续执行已经成功事务。

其他的等待测试。。。

阅读(7774) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chensiping2008-02-19 18:17:49

begin; create table foo2 (i int not null primary key) engine innodb; insert into foo2 values(1); insert into foo2 values(1); rollback; select * from foo2; +---+ | i | +---+ | 1 | +---+ __________________________ 这是否说明innodb是不具备事务呢 把create语句放在事务前面吧,这样你的文章更完美一些,呵呵

chensiping2008-02-19 18:10:14

结论是正确的,例子是有问题的

chensiping2008-02-19 16:58:11

innodb在事务中遇到alter create之类的语句就自动commit了 所以你的第二个例子其实说明不了什么的