MySQL 如何更改数据库表的数据库引擎
首先,确定MySQL数据库的类型,即其引擎是InnoDB还是MyISAM。要实现此目的,请使用information_schema.columns.tables中的engine列。
语法如下。
SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'yourDatabaseName'
AND TABLE_NAME = 'yourTableName';
在这里,我有一个名为“StudentInformations”的表-
mysql> create table StudentInformations
-> (
-> StudentId int not null auto_increment,
-> StudentFirstName varchar(20),
-> StudentLastName varchar(20),
-> Primary Key(StudentId)
-> );
Query OK,0 rows affected (0.57 sec)
现在,您可以使用上述语法的实现知道表正在使用InnoDB还是MyISAM。我们的数据库是“test”。
相同的查询如下所示-
mysql> select engine from information_schema.tables
-> where table_schema = 'test'
-> and table_name = 'StudentInformations';
以下是输出结果-
+--------+
| ENGINE |
+--------+
| InnoDB |
+--------+
1行以展示(0.05 sec)
使用alter命令更改“StudentInformations”表的引擎。以下是更改任何表的引擎的语法。
ALTER TABLE yourTableName ENGINE = 'yourEngineName';
现在,让我们将InnoDB引擎更改为MyISAM。查询如下-
mysql> alter table StudentInformations ENGINE = 'MyISAM';
Query OK,6 rows affected (1.84 sec)
Records − 6 Duplicates − 0 Warnings − 0
上面显示的结果显示有6行受到影响,因为表中有6行。
要检查表是否从InnoDB转换为MyISAM,以下是查询-
mysql> select engine from information_schema.tables
-> where table_schema = 'test'
-> and table_name = 'StudentInformations';
以下是显示引擎已成功更新的输出-
+--------+
| ENGINE |
+--------+
| MyISAM |
+--------+
1行以展示(0.00 sec)
阅读更多:MySQL 教程