获取MySQL中的表的行计数? [英] Getting row count for a table in MySQL?

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

问题描述

任何人都可以告诉我,在MySQL中,找到表格的行数是最好的办法:

Can anyone tell me which is he better appraoch in MySQL whin it comes to finding the row count of a table: is it better to do

SELECT COUNT(*) FROM TABLE_NAME

INFORMATION_SCHEMA

中的表计算页面的分页计数的频繁操作?

This would be a frequent operation for calculating pagination counts for pages?

我应该补充一点,表格最多只能有几千行。

I should add that tables will only have a few thousand rows at most.

感谢

Martin O'Shea。

Martin O'Shea.

推荐答案

MyISAM 中,查询:

SELECT  COUNT(*)
FROM    TABLE_NAME

是即时的,因为它保存在表元数据中,

is instant, since it's kept in the table metadata, so it's almost free to issue this query and it will always get the correct result.

InnoDB 中,此查询将计算行数,

In InnoDB, this query will count rows one-by-one which could take some time.

因此,如果你不需要 COUNT(*)的精确值,您可以查询 INFORMATION_SCHEMA

So if you don't need exact value of COUNT(*), you may query INFORMATION_SCHEMA.

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

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