admin管理员组

文章数量:1638806

一般要统计业务库中所有表的总行数的时候,都是直接查 information_schema 库中的 tables 表中的 table_rows 字段值:

SELECT
	table_name,
	table_rows,
	table_comment
FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'businessDB' ORDER BY table_rows DESC;

但是会发现和

select count(*) from 某张表;

执行得到的值是不相同的!那是因为

(1)默认情况下 mysql 对表进行增删操作时,是不会自动更新 information_schema 库中 tables 表的 table_rows 字段的,在网上搜索一下发现说:只有10%的行数发生变化才会自动收集(没有亲自验证过!);

(2)执行 Analyze table tableName; 会统计所有表数据(在生产环境中不建议使用,因为会锁表!);

本文标签: 字段informationschemamysqlTablescount