1. SHOW TABLES LIKE '%log%';
  1. SELECT table_name FROM information_schema.tables
  2. WHERE table_schema = DATABASE()
  3. AND table_name LIKE '%log%';

在 MySQL 命令行里,模糊查询表名 最常用、最方便的就是 SHOW TABLES 配合 LIKE 模糊匹配。

1. 基础语法(最常用)

  1. -- 模糊查询表名(匹配包含 xxx 的表)
  2. SHOW TABLES LIKE '%匹配内容%';

符号说明

  • %:匹配任意多个字符(包括 0 个)
  • _:匹配任意单个字符

2. 常用示例

① 查询包含 user 的表

  1. SHOW TABLES LIKE '%user%';

② 查询以 order 开头的表

  1. SHOW TABLES LIKE 'order%';

③ 查询以 log 结尾的表

  1. SHOW TABLES LIKE '%log';

④ 匹配单个字符(比如 t_1t_a

  1. SHOW TABLES LIKE 't__'; -- 两个下划线:匹配 t 开头 + 两个字符

3. 更精准:从系统库查询(支持更多条件)

  1. SELECT table_name
  2. FROM information_schema.tables
  3. WHERE table_schema = '你的数据库名'
  4. AND table_name LIKE '%user%';

示例:

  1. SELECT table_name
  2. FROM information_schema.tables
  3. WHERE table_schema = 'test_db'
  4. AND table_name LIKE '%order%';

4. 步骤总结(直接照抄用)

  1. 登录 MySQL
  2. 进入你的数据库
    1. USE 数据库名;
  3. 执行模糊查询
    1. SHOW TABLES LIKE '%关键字%';

总结

  • 最简单SHOW TABLES LIKE '%关键字%';
  • 最灵活:从 information_schema.tables 查询
  • 符号:% 任意字符,_ 单个字符