mysql查询数据库有多少表的方法:1、使用MySQL客户端登录到MySQL数据库服务器;2、使用“USE 数据库名”语句切换到指定的数据库中;3、使用“SHOW TABLES;”语句列出指定数据库中的所有表即可。
本教程操作环境:windows7系统、mysql8版本、Dell G3电脑。 在mysql中,可以利用 要在MySQL数据库中列出所有表,请按照下列步骤操作:
下面说明了MySQL SHOW TABLES; MySQL SHOW TABLES示例以下示例说明如何列出 步骤1 - 连接到MySQL数据库服务器: C:\Users\Administrator>mysql -u root -p 步骤2 -切换到 mysql> USE yiibaidb; Database changed mysql> 步骤3 - 显示 mysql> show tables; +--------------------+ | Tables_in_yiibaidb | +--------------------+ | aboveavgproducts | | article_tags | | bigsalesorder | | contacts | | customerorders | | customers | | departments | | employees | | employees_audit | | officeinfo | | offices | | offices_bk | | offices_usa | | orderdetails | | orders | | organization | | payments | | price_logs | | productlines | | products | | saleperorder | | user_change_logs | | v_contacts | | vps | +--------------------+ 24 rows in set
SHOW FULL TABLES; 执行上面语句,如下所示 - mysql> SHOW FULL TABLES; +--------------------+------------+ | Tables_in_yiibaidb | Table_type | +--------------------+------------+ | aboveavgproducts | VIEW | | article_tags | BASE TABLE | | bigsalesorder | VIEW | | contacts | BASE TABLE | | customerorders | VIEW | | customers | BASE TABLE | | departments | BASE TABLE | | employees | BASE TABLE | | employees_audit | BASE TABLE | | officeinfo | VIEW | | offices | BASE TABLE | | offices_bk | BASE TABLE | | offices_usa | BASE TABLE | | orderdetails | BASE TABLE | | orders | BASE TABLE | | organization | VIEW | | payments | BASE TABLE | | price_logs | BASE TABLE | | productlines | BASE TABLE | | products | BASE TABLE | | saleperorder | VIEW | | user_change_logs | BASE TABLE | | v_contacts | VIEW | | vps | VIEW | +--------------------+------------+ 24 rows in set 我们在 CREATE VIEW view_contacts AS SELECT lastName, firstName, extension as phone FROM employees UNION SELECT contactFirstName, contactLastName, phone FROM customers; 现在,执行查询 mysql> SHOW FULL TABLES; +--------------------+------------+ | Tables_in_yiibaidb | Table_type | +--------------------+------------+ | aboveavgproducts | VIEW | | article_tags | BASE TABLE | | bigsalesorder | VIEW | | contacts | BASE TABLE | | customerorders | VIEW | | customers | BASE TABLE | | departments | BASE TABLE | | employees | BASE TABLE | | employees_audit | BASE TABLE | | officeinfo | VIEW | | offices | BASE TABLE | | offices_bk | BASE TABLE | | offices_usa | BASE TABLE | | orderdetails | BASE TABLE | | orders | BASE TABLE | | organization | VIEW | | payments | BASE TABLE | | price_logs | BASE TABLE | | productlines | BASE TABLE | | products | BASE TABLE | | saleperorder | VIEW | | user_change_logs | BASE TABLE | | v_contacts | VIEW | | view_contacts | VIEW | | vps | VIEW | +--------------------+------------+ 25 rows in set 您可以看到, 对于具有很多表的数据库,一次显示所有表可能不免直观。 幸运的是, SHOW TABLES LIKE pattern; SHOW TABLES WHERE expression; 例如,要显示 mysql> SHOW TABLES LIKE 'p%'; +-------------------------+ | Tables_in_yiibaidb (p%) | +-------------------------+ | payments | | price_logs | | productlines | | products | +-------------------------+ 4 rows in set 或者显示以’ mysql> SHOW TABLES LIKE '%es'; +--------------------------+ | Tables_in_yiibaidb (%es) | +--------------------------+ | employees | | offices | | productlines | +--------------------------+ 3 rows in set 以下语句说明了如何在 mysql> SHOW FULL TABLES WHERE table_type = 'VIEW'; +--------------------+------------+ | Tables_in_yiibaidb | Table_type | +--------------------+------------+ | aboveavgproducts | VIEW | | bigsalesorder | VIEW | | customerorders | VIEW | | officeinfo | VIEW | | organization | VIEW | | saleperorder | VIEW | | v_contacts | VIEW | | view_contacts | VIEW | | vps | VIEW | +--------------------+------------+ 9 rows in set 有时,希望看到非当前使用的数据库中的表。可以使用 以下示例演示如何显示以’ mysql> SHOW TABLES FROM mysql LIKE 'time%'; +---------------------------+ | Tables_in_mysql (time%) | +---------------------------+ | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | +---------------------------+ 5 rows in set 以下语句相当于上面的语句,但它使用 mysql> SHOW TABLES IN mysql LIKE 'time%'; +---------------------------+ | Tables_in_mysql (time%) | +---------------------------+ | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | +---------------------------+ 5 rows in set 请注意,如果您没有基表或视图的权限,则它不会显示在 【相关推荐:mysql视频教程】 以上就是mysql怎么查询数据库有多少表的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |
