关于mysql事务不能回滚的原因:
START TRANSACTION;
DML 语句;
ROLLBACK;
在mysql工具中执行sql语句实现回滚,如能实现,则是代码问题,如不能实现有一下原因:
原因1.Mysql数据库引擎使用的是默认的MyISAM,输入SHOW ENGINES 语句
如果红线属性为YES说明引擎是支持事务,否则要进行修改,修改方法如下:
1.找到mysql安装路径下的my.ini文件 ,添加default-storage-engine=InnoDB 语句 设置默认引擎为innoDB
2.重启mysql .重新查询结果
原因2:表的引擎不是innoDB
修改某个表的存储引擎为innodb:
alter table table_name engine=innodb;
注意:修改或者操作某个表之前首先要进入某个表所在的数据库中,使用use db_name go;,之后再进行增删改查操作。
查看表使用的存储引擎
两种方法:
a、show table status from db_name where name=‘table_name’;
b、show create table table_name;
3.mysql当前默认的存储引擎:show variables like ‘%storage_engine%’;
4.某个表用了什么引擎:show create table 表名;