获取MySQL数据库中所有表的记录计数 [英] Get record counts for all tables in MySQL database

查看:158
本文介绍了获取MySQL数据库中所有表的记录计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不对每个表运行SELECT count()的情况下获取MySQL数据库中所有表的行数?

Is there a way to get the count of rows in all tables in a MySQL database without running a SELECT count() on each table?

推荐答案

SELECT SUM(TABLE_ROWS) 
     FROM INFORMATION_SCHEMA.TABLES 
     WHERE TABLE_SCHEMA = '{your_db}';

文档中的注释:对于InnoDB表中,行数只是SQL优化中使用的粗略估计.您需要使用COUNT(*)进行精确计数(这比较昂贵).

Note from the docs though: For InnoDB tables, the row count is only a rough estimate used in SQL optimization. You'll need to use COUNT(*) for exact counts (which is more expensive).

这篇关于获取MySQL数据库中所有表的记录计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆