mysql查询数据库中的表名_mysql 查询数据库中的表名

查询一个数据库中含有某关键词的表名

搜索一个数据库中包含一些关键字,词的表。

SELECT

TABLE_NAME

FROM

information_schema. TABLES

WHERE

table_schema = '数据库名'

AND TABLE_NAME LIKE '%name%';

mysql> select table_name from information_schema.tables

-> where table_schema = 'sakila'

-> and table_name like "%film%";

+----------------------------+

| TABLE_NAME |

+----------------------------+

| film |

| film_actor |

| film_category |

| film_list |

| film_text |

| nicer_but_slower_film_list |

| sales_by_film_category |

+----------------------------+

7 rows in set (0.00 sec)

查询数据库中所有的表

show tables;

-- use 数据库名

USE sakila;

SHOW TABLES;

同上面,where条件只查数据库名。还可以同时搜索多个数据库中的表。

SELECT

TABLE_NAME

FROM

information_schema. TABLES

WHERE

table_schema = '数据库名';

mysql> select table_name from information_schema.tables where table_schema = 'sakila';

+----------------------------+

| TABLE_NAME |

+----------------------------+

| actor |

| actor_info |

| address |

| category |

| city |

| country |

| customer |

| customer_list |

| film |

| film_actor |

| film_category |

| film_list |

| film_text |

| inventory |

| language |

| nicer_but_slower_film_list |

| payment |

| rental |

| sales_by_film_category |

| sales_by_store |

| staff |

| staff_list |

| store |

+----------------------------+

23 rows in set (0.00 sec)

mysql> select table_name from information_schema.tables where table_schema = 'sakila' or table_schema = 'test';

+----------------------------+

| TABLE_NAME |

+----------------------------+

| actor |

| address |

| category |

| city |

| country |

| customer |

| film |

| film_actor |

| film_category |

| film_text |

| inventory |

| language |

| payment |

| rental |

| staff |

| store |

| customer_list |

| film_list |

| nicer_but_slower_film_list |

| staff_list |

| sales_by_store |

| sales_by_film_category |

| actor_info |

| employee |

| test_alter |

+----------------------------+

25 rows in set (0.01 sec)

以上。

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值