在MySQL里这条命令非常常见,显示your-db-name数据库中所有有数据的表名,按数据条数由高到低排序,
select table_name, table_rows from information_schema.tables where
TABLE_SCHEMA = ‘your-db-name’ AND table_rows > 0 order BY
table_rows DESC;
但用多了你会发现,在默认情况下这条命令的数字并不准确。
用下面的命令激活你指定表的统计
use your-db-name; Analyze TABLE your-table-name1; Analyze TABLE your-table-name2; …
再执行
select table_name, table_rows from information_schema.tables where
TABLE_SCHEMA = ‘your-db-name’ AND table_rows > 0 order BY
table_rows DESC;
就可以得准确的数字。
单个表格可以这样得到准确的数据
SELECT COUNT(*) FROM 表名称