本文介绍云数据库 MySQL 版提供的将 MyISAM、Memory 和 Archive 存储引擎自动转换为 InnoDB 存储引擎功能的相关信息。
火山引擎云数据库 MySQL 版默认支持 InnoDB 存储引擎,不支持 MyISAM、Memory 或 Archive 存储引擎。为方便数据库迁移或升级,提供了将 MyISAM、Memory 和 Archive 存储引擎自动转换为 InnoDB 存储引擎的功能。
MySQL 5.7 版本,内核小版本为 MySQL 5.7.32_20250415 及以上。
MySQL 8.0 版本,内核小版本为 MySQL 8.0.32_20250415 及以上。
说明
您可通过查看实例信息查看实例的内核小版本。如您实例的内核小版本未在受支持的内核小版本范围内,您可可手动升级实例内核小版本。
用户建表时指定存储引擎为 MyISAM、Memory 或 Archive,会被自动转换为 InnoDB 存储引擎。
mysql> create table t(a int) engine = myisam; Query OK, 0 rows affected, 2 warnings (0.14 sec) mysql> show create table t\G *************************** 1. row *************************** Table: t Create Table: CREATE TABLE `t` ( `a` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)
用户建表时不指定存储引擎,但设置默认引擎为 MyISAM、Memory 或 Archive 时,如 default_storage_engine = 'myisam'
,也会被自动转换为 InnoDB 存储引擎。
mysql> set global default_storage_engine = 'myisam'; Query OK, 0 rows affected (0.00 sec) mysql> create table t(a int); Query OK, 0 rows affected (0.12 sec) mysql> show create table t\G *************************** 1. row *************************** Table: t Create Table: CREATE TABLE `t` ( `a` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)
如果您需要关闭自动转换功能,可将参数 loose_convert_disabled_engines_to_innodb
的运行值设置为 off
。更多关于修改参数的详细信息,请参见修改参数。
MyISAM 引擎支持复合主键包含自增列,而 InnoDB 引擎不支持,因此 MyISAM 引擎转换为 InnoDB 引擎后,创建表时会报错,报错信息为:
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
建议您通过为自增列创建索引的方式,实现 InnoDB 引擎的复合主键包含自增列语法。示例如下:
mysql> create table t_multikey ( -> id int AUTO_INCREMENT, -> name varchar(20), -> address varchar(20), -> primary key (name,id) -> ) ENGINE=MyISAM; ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
修改方案如下,可以看到该表被成功创建,且创建为 InnoDB 存储引擎:
mysql> create table t_multikey ( -> id int AUTO_INCREMENT, -> name varchar(20), -> address varchar(20), -> primary key (name,id), -> key idx_id(id) -> ) ENGINE=MyISAM; Query OK, 0 rows affected, 2 warnings (0.11 sec) mysql> show warnings; +---------+------+-------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------------+ | Warning | 3161 | Storage engine MyISAM is disabled (Table creation is disallowed). | | Warning | 1266 | Using storage engine InnoDB for table 't_multikey' | +---------+------+-------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> show create table t_multikey\G *************************** 1. row *************************** Table: t_multikey Create Table: CREATE TABLE `t_multikey` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `address` varchar(20) DEFAULT NULL, PRIMARY KEY (`name`,`id`), KEY `idx_id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)