本文章給各位朋友簡(jiǎn)單的介紹一下關(guān)于mysql中查看數(shù)據(jù)庫(kù)中所有表的記錄數(shù)實(shí)現(xiàn)方法,有需了的朋友可參考.
如果使用mysql的版本在5.0及以上,可以通過(guò)查詢information_schema庫(kù)中的tables表來(lái)獲取,該表中使用table_rows記錄表的行數(shù)信息,例如查看庫(kù)testdb中所有表的記錄數(shù),代碼如下:
- use information_schema;
- --Vevb.com
- select table_name,table_rows from tables
- where TABLE_SCHEMA = 'testdb'
- order by table_rows desc;
不過(guò)需要注意的是,對(duì)于InnoDB表,table_rows行計(jì)數(shù)僅是大概估計(jì)值,另外一種辦法還是借助information_schema庫(kù)的tables表,來(lái)拼接出一個(gè)條sql語(yǔ)句,代碼如下:
- use information_schema;
- select concat(
- 'select "',
- TABLE_name,
- '", count(*) from ',
- TABLE_SCHEMA,
- '.',
- TABLE_name,
- ' union all'
- ) from tables
- where TABLE_SCHEMA='testdb';
記錄一下mysql中查看所有表的記錄數(shù):
TABLE_SCHEMA:數(shù)據(jù)庫(kù)名
TABLE_NAME:表名
ENGINE:所使用的存儲(chǔ)引擎
TABLES_ROWS:記錄數(shù)
DATA_LENGTH:數(shù)據(jù)大小 得到的結(jié)果是以字節(jié)為單位,除1024為K,除1048576(=1024*1024)為M
INDEX_LENGTH:索引大小
實(shí)例代碼如下:
- use information_schema;
- select table_schema,table_name,table_rows from tables order by table_rows desc;
查看指定數(shù)據(jù)庫(kù)大小,代碼如下:
SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='數(shù)據(jù)庫(kù)名';
得到的結(jié)果是以字節(jié)為單位,除1024為K,除1048576(=1024*1024)為M.
新聞熱點(diǎn)
疑難解答
圖片精選