ใช้ ALTER TABLE ... ENGINE=... เปลี่ยน Storage Engine
ไวยากรณ์
alter table yourTableName ENGINE=InnoDB;
สร้างตาราง Engine=MyISAM
mysql> create table DemoTable (
-> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> StudentName varchar(20),
-> StudentAge int,
-> StudentCountryName varchar(20)
-> ) ENGINE=MyISAM, AUTO_INCREMENT=101;
Query OK, 0 rows affected (0.18 sec)
ตรวจสอบ Engine ก่อนเปลี่ยน
mysql> show create table DemoTable;
ENGINE=MyISAM
คิวรี่เปลี่ยนเป็น InnoDB
mysql> alter table DemoTable ENGINE=InnoDB; Query OK, 0 rows affected (1.21 sec) Records: 0 Duplicates: 0 Warnings: 0
ตรวจสอบหลังเปลี่ยน
mysql> show create table DemoTable;
ENGINE=InnoDB
Engine หลัก: InnoDB (default, รองรับ Transaction, FK) | MyISAM (เก่า, เร็วใน SELECT, ไม่มี Transaction) | Memory, Archive, CSV, etc. | การเปลี่ยน Engine จะ rebuild ตาราง อาจนานถ้าข้อมูลเยอะ