我可以在MySQL的单个数据库中使用InnoDB和MyISAM表吗?

是的,您可以在一个数据库中使用InnoDB和MyISAM表,或者将它们合并在一个数据库中。这是推荐的方法。

这是一个数据库中MyISAM和InnoDB的演示。以下是数据库以及表类型InnoDB和MyISAM。创建数据库的查询如下-

create database BothInnoDBandMyISAM;
use BothInnoDBandMyISAM;
Database changed

我有一个名为“ BothInnoDBandMyISAM”的数据库。

首先,该表具有引擎类型InnoDB。使用引擎InnoDB创建表的查询如下-

create table Student
   -> (
   -> StudentId int,
   -> StudentName varchar(20)
   -> )ENGINE=InnoDB;

第二个表的引擎类型为MyISAM。使用引擎MyISAM创建表的查询如下-

create table Employee
   -> (
   -> EmployeeId int,
   -> EmployeeName varchar(30)
   -> )ENGINE=MyISAM;

这是从同一数据库检查引擎类型的查询。对第一个表的查询如下。

select engine from information_schema.tables where table_name='Student' and table_schema='BothInnoDBandMyISAM';

以下是输出-

+--------+
| ENGINE |
+--------+
| InnoDB |
+--------+
1 row in set (0.00 sec)

这是检查来自同一数据库的表引擎类型的查询。对于第二个表,查询如下。

select engine from information_schema.tables where table_name='Employee' and table_schema='BothInnoDBandMyISAM';

以下是输出-

+--------+
| ENGINE |
+--------+
| MyISAM |
+--------+
1 row in set (0.00 sec)