在使用阿里云进行服务器开发时,遇到一个问题,mysql的事务功能不作用,查阅资料后发现是table默认的引擎不支持事务功能,只需将table的引擎模式调整为InnoDB即可,特此备忘:
环境说明:阿里云centos 6.5 64位
mysql版本 :5.1.73
操作步奏
1.进入mysql
mysql -u root -p
2.查看mysql默认引擎模式
show engines;
显示结果如下
--------------
show engines
--------------
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)
看到支持事务(transaction)的引擎模式只有InnoDB 而默认的MyIAS
PS:mysql在5.5版本之后默认驱动方式已经成为InnoDB,所以修改前请先确认
修改数据库默认引擎模式
set storage_engine = InnoDB;
show engines;
结果如下
--------------
show engines
--------------
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | YES | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)
现在数据库的默认驱动方式已经变成InnoDB