ใช้ CREATE TABLE ... LIKE คัดลอกโครงสร้าง (รวม Indexes) แล้วตามด้วย INSERT ... SELECT คัดลอกข้อมูล
ตัวอย่าง Clone ตาราง student:
mysql> DESC student; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | int(11) | YES | MUL | NULL | | | Name | varchar(100) | YES | MUL | NULL | | +-------+--------------+------+-----+---------+-------+ mysql> SELECT * FROM student; +------+------+ | id | Name | +------+------+ | 1 | John | | 2 | Bob | +------+------+
Clone:
mysql> CREATE TABLE cloneStudent LIKE student; Query OK, 0 rows affected (1.57 sec) mysql> INSERT INTO cloneStudent SELECT * FROM student; Query OK, 2 rows affected (0.60 sec)
ตรวจสอบโครงสร้างและข้อมูล:
mysql> DESC cloneStudent; -- โครงสร้างเหมือนกันทุกอย่าง รวม Indexes mysql> SELECT * FROM cloneStudent; -- ข้อมูลเหมือนกัน
ข้อดี: คัดลอก Column definitions, Indexes, Constraints, Engine, Charset ทั้งหมด