mysql 檢視資料庫 表 大小

2021-09-01 08:08:45 字數 2105 閱讀 6455

記錄備忘

1、進去指定schema 資料庫(存放了其他的資料庫的資訊)

use information_schema

2、查詢所有資料的大小

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables

3、檢視指定資料庫的大小

比如說 資料庫apoyl

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='apoyl';

4、檢視指定資料庫的表的大小

比如說 資料庫apoyl 中apoyl_test表

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='apoyl' and table_name='apoyl_test';

大家在安裝或使用mysql時,會發現除了自己安裝的資料庫以外,還有乙個information_schema資料庫。information_schema資料庫是做什麼用的呢,使用wordpress部落格的朋友可能會想,是不是安裝模板新增的資料庫呀?看完本片文章後,你就會對information_schema資料庫有所了解。

information_schema資料庫是mysql自帶的,它提供了訪問資料庫元資料的方式。什麼是元資料呢?元資料是關於資料的資料,如資料庫名或表名,列的資料型別,或訪問許可權等。有些時候用於表述該資訊的其他術語包括「資料詞典」和「系統目錄」。

在mysql中,把 information_schema 看作是乙個資料庫,確切說是資訊資料庫。其中儲存著關於mysql伺服器所維護的所有其他資料庫的資訊。如資料庫名,資料庫的表,表欄的資料型別與訪問許可權等。在information_schema中,有數個唯讀表。它們實際上是檢視,而不是基本表,因此,你將無法看到與之相關的任何檔案。

information_schema資料庫表說明:

schemata表:提供了當前mysql例項中所有資料庫的資訊。是show databases的結果取之此表。

tables表:提供了關於資料庫中的表的資訊(包括檢視)。詳細表述了某個表屬於哪個schema,表型別,表引擎,建立時間等資訊。是show tables from schemaname的結果取之此表。

columns表:提供了表中的列資訊。詳細表述了某張表的所有列以及每個列的資訊。是show columns from schemaname.tablename的結果取之此表。

statistics表:提供了關於表索引的資訊。是show index from schemaname.tablename的結果取之此表。

user_privileges(使用者許可權)表:給出了關於全程許可權的資訊。該資訊源自mysql.user授權表。是非標準表。

schema_privileges(方案許可權)表:給出了關於方案(資料庫)許可權的資訊。該資訊來自mysql.db授權表。是非標準表。

table_privileges(表許可權)表:給出了關於表許可權的資訊。該資訊源自mysql.tables_priv授權表。是非標準表。

column_privileges(列許可權)表:給出了關於列許可權的資訊。該資訊源自mysql.columns_priv授權表。是非標準表。

character_sets(字符集)表:提供了mysql例項可用字符集的資訊。是show character set結果集取之此表。

collations表:提供了關於各字符集的對照資訊。

table_constraints表:描述了存在約束的表。以及表的約束型別。

key_column_usage表:描述了具有約束的鍵列。

routines表:提供了關於儲存子程式(儲存程式和函式)的資訊。此時,routines表不包含自定義函式(udf)。名為「mysql.proc name」的列指明了對應於information_schema.routines表的mysql.proc表列。

views表:給出了關於資料庫中的檢視的資訊。需要有show views許可權,否則無法檢視檢視資訊。

triggers表:提供了關於觸發程式的資訊。必須有super許可權才能檢視該錶。

mysql檢視資料庫大小或者表大小

要想知道每個資料庫的大小的話,步驟如下 1 進入information schema 資料庫 存放了資料庫的資訊 use information schema 2 查詢所有資料庫的大小 select concat round sum data length 1024 1024 2 mb as dat...

MYSQL 檢視資料庫大小以及表的大小

在mysql的information schema資料庫下執行 一 檢視每個資料庫的大小 select table schema,concat round sum data length 1024 1024 2 mb as data from tables group by table schema...

檢視mysql資料庫大小

資料量大的情況下 謹慎使用 mysql會崩潰!資料量大的情況下 謹慎使用 mysql會崩潰!資料量大的情況下 謹慎使用 mysql會崩潰!mysql檢視當前所有的資料庫和索引大小 select table schema,concat truncate sum data length 1024 102...