1. 区别
-
show tables:简单读取了mysql对应数据库目录下所有.frm文件就返回了,甚至不校验frm是否合法。
-
show full tables: 获取mysql的表类型,并且会打开所有涉及表的.frm文件一次以获取Table_type,如果frm异常,Table_type会提示ERROR。
-
select TABLE_SCHEMA,table_name,table_type from information_schema.tables where table_schema='test': 从TABLE_SHARE+information_schema.tables中获取表信息。(table_share相当于.frm文件的缓存,get_table_share获取表元数据缓存,如果表没打开过,也会实际去读.frm打开表,这种情况也慢)。
2. 性能
show tables > select * from information_schema.tables > show full tables;
实际上,在生产环境中,基本上全部表都是打开状态,(table_open_cache设置的很大的话),从information_schema读取,性能也会远远高于show full tables。
3. 示例
为了显示各个命令的区别,在test库下touch了一个 t3.frm 空文件;
1. show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1 |
| t2 |
| t3 |
+----------------+
2. show full tables;
+----------------+------------+
| Tables_in_test | Table_type |
+----------------+------------+
| t1 | BASE TABLE |
| t2 | BASE TABLE |
| t3 | ERROR |
+----------------+------------+
3. select TABLE_SCHEMA,table_name,table_type from information_schema.tables where table_schema='test';
+--------------+------------+------------+
| TABLE_SCHEMA | table_name | table_type |
+--------------+------------+------------+
| test | t1 | BASE TABLE |
| test | t2 | BASE TABLE |
+--------------+------------+------------+
参考文档: