標籤:schema htm null 資料 mys row har gpo rem
1、說明
大家在安裝或使用MYSQL時,會發現除了自己安裝的資料庫以外,還有一個 information_schema資料庫。information_schema資料庫是MySQL內建的,它提供了訪問資料庫中繼資料的方式。中繼資料是關於資料的資料,如資料庫名或表名,列的資料類型,或存取權限等。有些時候用於表述該資訊的其他術語包括“資料詞典”和“系統目錄”。
information_schema是資訊資料庫,其中儲存著關於mysql伺服器所維護的所有其他資料庫的資訊。在information_schema中,有數個唯讀表。它們實際上是視圖,而不是基本表,因此,你將無法看到與之相關的任何檔案,也就是information_schema說一個虛擬資料庫,物理上並不存在。具體看:
事實上,儘管不需要產生名為information_schema的檔案,我們仍提供了名為information_schema的新資料庫。可以使用USE語句將information_schema選擇為預設資料庫,但訪問該資料庫中所含表的唯一方式是使用SELECT語句。不能在其中插入內容,不能更新它們,也不能刪除其中的內容
每位MySQL使用者均有權訪問這些表,但僅限於表中的特定行,在這類行中含有使用者具有恰當存取權限的對象
與SHOW相比,SELECT的優點
SELECT ... FROM information_schema語句的目的在於提供一種更為一致的方式,以訪問MySQL所支援的各種SHOW語句(SHOW DATABASES、SHOW TABLES等等)提供的資訊。與SHOW相比,使用SELECT有多項優點“
· 符合Codd規則。也就是說,所有訪問均是在表上進行的。
· 不需要瞭解新語句的文法。由於他們已知道SELECT的工作方式,僅需瞭解對象名即可。
· 實現人無需操心增加關鍵詞方面的事宜。
· 有數百萬種可能的輸出變化,而不是一種。這樣,就為對中繼資料有不同需求的應用程式提供了更高的靈活性。
· 由於其他DBMS也採用了這類方式,移植更為容易。
然而,由於SHOW在MySQL的僱員和使用者中十分流行,如果SHOW消失,可能會導致混亂,因此傳統的文法方式無法給出消除SHOW的足夠理由。事實上,在MySQL 5.1中,還對SHOW進行了多項增強。關於這方面的介紹,請參見“SHOW語句的擴充”。
2、information_schema下的表
2.1 schemata表
schemata表提供了當前mysql執行個體中所有資料庫的資訊。show databases的結果取之此表。該表對應的列說明如下:
| 列名 |
中文解釋 |
例子 |
| catalog_name |
|
|
| schema_name |
資料庫名 |
|
| default_character_set_name |
資料庫預設編碼 |
utf8 |
| default_collation_name |
|
utf8_general_ci |
| sql_path |
|
null |
注釋:SQL_PATH列的之總為NULL。
下述語句是等效的:
select schema_name as `database`
from information_schema.schemata
[where schema_name like ‘db_ca_ods‘]
show databases
[like ‘db_ca_ods‘]
2.2 tables表
tables表提供了關於資料庫中的表的資訊(包括視圖)。詳細表述了某個表屬於哪個schema,表類型,表引擎,建立時間等資訊。是show tables from db_ca_ods;【注db_ca_ods為資料庫名】的結果取之此表。
| 列名 |
中文解釋 |
例子/說明 |
| TABLE_CATALOG |
|
NULL |
| table_schema |
資料庫名稱 |
information_schema |
| table_name |
表名 |
tables表,屬於information_schema資料庫 |
| table_type |
表類型 |
應是BASE TABLE(基本表)或VIEW(視圖)。如果表是臨時性的,TABLE_TYPE = TEMPORARY。(沒有臨時視圖,因此,因此不存在歧義) |
| engine |
表所用引擎 |
InnoDB |
| version |
Version |
|
|
row_format |
Row_format |
|
|
table_rows |
表中總行數 |
|
|
avg_row_length |
Avg_row_length |
|
|
data_length |
Data_length |
|
|
max_data_length |
Max_data_length |
|
|
index_length |
Index_length |
|
|
data_free |
Data_free |
|
|
auto_increment |
Auto_increment |
|
|
create_time |
Create_time |
|
|
update_time |
Update_time |
|
|
check_time |
Check_time |
|
|
table_collation |
Collation |
|
|
checksum |
Checksum |
|
|
create_options |
Create_options |
|
|
table_comment |
Comment |
表的說明,及create語句中comment的值 |
下述語句是等效的:
select table_name from information_schema.tables
[where table_schema = ‘db_name‘]
[where|and table_name like ‘wild‘]
show tables
[from db_name]
[like ‘wild‘]
mysql中information_schema說明