mysql 查看數(shù)據(jù)庫中所有表的記錄數(shù)
mysql使用select count(*) from table_name可以查詢某個(gè)表的總記錄數(shù)。想快速的知道數(shù)據(jù)庫中所有表的記錄數(shù)信息怎么辦?如果使用mysql的版本在5.0及以上,可以通過查詢information_schema庫中的tables表來獲取,該表中使用table_rows記錄表的行數(shù)信息。例如查看庫testdb中所有表的記錄數(shù):
use?information_schema; select?table_name,table_rows?from?tables? where?TABLE_SCHEMA?=?'testdb'? order?by?table_rows?desc;
不過需要注意的是,對于InnoDB表,table_rows行計(jì)數(shù)僅是大概估計(jì)值。
另外一種辦法還是借助information_schema庫的tables表,來拼接出一個(gè)條sql語句,例如:
use?information_schema; select?concat( ????'select?"',? ????TABLE_name,? ????'",?count(*)?from?',? ????TABLE_SCHEMA,? ????'.', ????TABLE_name, ????'?union?all' )?from?tables? where?TABLE_SCHEMA='testdb';
把生成的結(jié)果手動(dòng)加工一下就行了,起碼比一張張表去拼寫要來的快。