如何在 MySQL 中將 MyISAM 轉換為 InnoDB 儲存引擎?


要將 MyISAM 引擎轉換為 InnoDB,我們可以使用 ALTER 命令。我們現在使用 MyISAM 引擎建立一個表。

mysql> create table MyISAMToInnoDBDemo
   -> (
   -> id int,
   -> Name varchar(100)
   -> )ENGINE=MyISAM;
Query OK, 0 rows affected (0.19 sec)

檢查該表是否使用 MyISAM 引擎建立。

mysql> SELECT TABLE_NAME,ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'business' and ENGINE = 'MyISAM';

以下是顯示使用 MyISAM 引擎建立的表的輸出。

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

我們可以使用 ALTER 命令將 MyISAM 轉換為 InnoDB。

mysql> alter table MyISAMToInnoDBDemo engine=InnoDB;
Query OK, 0 rows affected (1.65 sec)
Records: 0  Duplicates: 0  Warnings: 0

檢查轉換。

mysql> SELECT TABLE_NAME,ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'test' and ENGINE = 'InnoDB';

以下是輸出。

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

更新日期:30-7-2019

260 瀏覽量

開始您的職業生涯

完成課程即可獲得認證

開始學習
廣告