robin@localhost[sakila]> explain select * from actor_like_isam where last_name like 'A%';
+----+-------------+-----------------+-------+---------------------+---------------------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------+-------+---------------------+---------------------+---------+------+------+-----------------------+
| 1 | SIMPLE | actor_like_isam | range | idx_actor_last_name | idx_actor_last_name | 137 | NULL | 6 | Using index condition |
+----+-------------+-----------------+-------+---------------------+---------------------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
--从上面的测试可以看出基于myisam引擎方式对原表结构也是使用完成克隆方式
5、小结
a、create table like方式会完整地克隆表结构,但不会插入数据,需要单独使用insert into或load data方式加载数据
b、create table as 方式会部分克隆表结构,完整保留数据
c、create table as select .. where 1=0 会克隆部分表结构,但不克隆数据。
d、如果启用了gtid,create table as方式不被支持。收到ERROR 1786 (HY000): CREATE TABLE ... SELECT is forbidden when @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1.