mysql报错回滚并提示_mysql的engine不同,导致事物回滚失败的问题

近期在项目上遇到遇到一个头疼的问题,前方销售团队反馈了一个客户那边在创建用户(save object to DB)报错了以后,前台展示了错误,但是数据库却保存了这条记录。

接到这个BUG以后,第一时间查看了事物是否正确回滚,排查了代码后发现事物回滚成功,并且在我的环境下回滚成功,错误没有复现,

这个时候就比较棘手了,客户的事物回滚失败,但是我们的回滚成功,我们的项目使用的是grails框架做的,查询了grails声明性事物回滚的规则,我们的代码没有问题,那我就把问题转移到了数据库身上,

要了客户的数据库,以SQL的形式把数据库到出来,和我本地的数据库表进行比对,在比对的过程中发现了不同之处

客户的SQL(mysql)

ENGINE=MyISAM AUTO_INCREMENT=522 DEFAULT CHARSET=utf8

ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8

我们的SQL

发现问题所在,我们用的数据库引擎是InnoDB,而客户使用的是MYISAM,查询这两种引擎不同之处

https://dev.mysql.com/doc/refman/5.6/en/storage-engines.html

MySQL 5.6Supported Storage Engines

InnoDB: Thedefault storage engine in MySQL 5.6. InnoDB is a transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data. InnoDB row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent nonlocking reads increase multi-user concurrency and performance. InnoDB stores user data in clustered indexes to reduce I/O for common queries based on primary keys. To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints. For more information about InnoDB, see Chapter 14, The InnoDB Storage Engine.

MyISAM: These tables have a small footprint.Table-level locking limits the performance in read/write workloads, so it is often used in read-only or read-mostly workloads in Web anddata warehousing configurations.

Memory: Storesall data in RAM, for fast access in environments that require quick lookups of non-critical data. This engine was formerly known as the HEAP engine. Its use cases are decreasing; InnoDB with its buffer pool memory area provides a general-purpose and durable way to keep most or all data in memory, and NDBCLUSTER provides fast key-value lookups for huge distributeddata sets.

CSV: Its tables are reallytext files with comma-separated values. CSV tables let you import or dump data in CSV format, to exchange data with scripts and applications that read and write that same format. Because CSV tables are not indexed, you typically keep the data in InnoDB tables during normal operation, and only use CSV tables during the import orexport stage.

Archive: These compact, unindexed tables are intendedfor storing and retrieving large amounts of seldom-referenced historical, archived, orsecurity audit information.

Blackhole: The Blackhole storage engine accepts but doesnot store data, similar to the Unix /dev/null device. Queries always return an empty set. These tables can be used in replication configurations where DML statements are sent to slave servers, but the master server does not keep its own copy ofthe data.

NDB (also knownas NDBCLUSTER)—This clustered database engine is particularly suited for applications that require the highest possible degree of uptime and availability.

InnoDB支持事物,而MyISAM不支持事物,

在次复现错误,错误复现出来。

解决方式:

修改这张表的engine

alter table user engine=InnoDB

修改后再次测试,事物回滚成功。

bug解决。

为了避免再次创建表的engine是MyISAM引擎,修改mysql默认引擎,在修改之前查看数据库支持的所有引擎

mysql>show engines;+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

| Engine | Support | Comment | Transactions | XA | Savepoints |

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |

| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |

| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |

| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |

| MyISAM | YES | MyISAM storage engine | NO | NO | NO |

| CSV | YES | CSV storage engine | NO | NO | NO |

| ARCHIVE | YES | Archive storage engine | NO | NO | NO |

| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |

| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

存在InnoDB

在配置文件my.cnf中的 [mysqld] 下面加入default-storage-engine=INNODB 一句,保存。

重启mysql服务器:mysqladmin -u root -p shutdown或者service mysqld restart 登录mysql数据库,在mysql>提示符下搞入show engines;命令。如果出现 InnoDB |DEFAULT,则表示我们 设置InnoDB为默认引擎成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值