站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > MySQL 5.1参考手册中文版

Chapter聽23.聽The INFORMATION_SCHEMA Information Database - MySQL 5.1参考手册中文版

绗23绔狅細INFORMATION_SCHEMA淇℃伅鏁版嵁搴

INFORMATION_SCHEMA鎻愪緵浜嗚闂暟鎹簱鍏冩暟鎹殑鏂瑰紡銆

鍏冩暟鎹槸鍏充簬鏁版嵁鐨勬暟鎹紝濡傛暟鎹簱鍚嶆垨琛ㄥ悕锛屽垪鐨勬暟鎹被鍨嬶紝鎴栬闂潈闄愮瓑銆傛湁浜涙椂鍊欑敤浜庤〃杩拌淇℃伅鐨勫叾浠栨湳璇寘鎷滄暟鎹瘝鍏糕濆拰鈥滅郴缁熺洰褰曗濄

渚嬪锛

mysql> SELECT table_name, table_type, engine
-> FROM information_schema.tables
-> WHERE table_schema = 'db5'
-> ORDER BY table_name DESC;
 table_name锛堣〃鍚嶏級
 table_type锛堣〃绫诲瀷锛
 寮曟搸
 v56  
 VIEW锛堣鍥撅級
 NULL
 v3

VIEW锛堣鍥撅級

 NULL
 v2

VIEW锛堣鍥撅級

 NULL
 v

VIEW锛堣鍥撅級

 NULL
 tables 
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 t7
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 t3
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 t2
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 t
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 pk
 BASE TABLE锛堝熀鏈〃锛
 InnoDB 
 loop 
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 kurs 
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 k
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 into 
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 goto 
 BASE TABLE锛堝熀鏈〃锛
 MyISAM 
 fk2  
 BASE TABLE锛堝熀鏈〃锛
 InnoDB 
 fk
 BASE TABLE锛堝熀鏈〃锛
 InnoDB 
闆嗗悎涓惈17琛岋紙0.01绉掞級銆

瑙i噴锛氳璇彞璇锋眰鎸夐嗗悜瀛楁瘝椤哄簭鍒楀嚭鏁版嵁搴揹b5涓殑鎵鏈夎〃锛屼絾浠呮樉绀轰笁绉嶄俊鎭細琛ㄥ悕锛岃〃绫诲瀷锛屼互鍙婅〃寮曟搸銆

INFORMATION_SCHEMA鏄俊鎭暟鎹簱锛屽叾涓繚瀛樼潃鍏充簬MySQL鏈嶅姟鍣ㄦ墍缁存姢鐨勬墍鏈夊叾浠栨暟鎹簱鐨勪俊鎭傚湪INFORMATION_SCHEMA涓紝鏈夋暟涓彧璇昏〃銆傚畠浠疄闄呬笂鏄鍥撅紝鑰屼笉鏄熀鏈〃锛屽洜姝わ紝浣犲皢鏃犳硶鐪嬪埌涓庝箣鐩稿叧鐨勪换浣曟枃浠躲

姣忎綅MySQL鐢ㄦ埛鍧囨湁鏉冭闂繖浜涜〃锛屼絾浠呴檺浜庤〃涓殑鐗瑰畾琛岋紝鍦ㄨ繖绫昏涓惈鏈夌敤鎴峰叿鏈夋伆褰撹闂潈闄愮殑瀵硅薄銆

SELECT鐨勪紭鐐

SELECT ... FROM INFORMATION_SCHEMA璇彞鐨勭洰鐨勫湪浜庢彁渚涗竴绉嶆洿涓轰竴鑷寸殑鏂瑰紡锛屼互璁块棶MySQL鎵鏀寔鐨勫悇绉峉HOW璇彞锛SHOW DATABASESSHOW TABLES绛夌瓑锛夋彁渚涚殑淇℃伅銆備笌SHOW鐩告瘮锛屼娇鐢⊿ELECT鏈夊椤逛紭鐐光

         绗﹀悎Codd瑙勫垯銆備篃灏辨槸璇达紝鎵鏈夎闂潎鏄湪琛ㄤ笂杩涜鐨勩

         涓嶉渶瑕佷簡瑙f柊璇彞鐨勮娉曘傜敱浜庝粬浠凡鐭ラ亾SELECT鐨勫伐浣滄柟寮忥紝浠呴渶浜嗚В瀵硅薄鍚嶅嵆鍙

         瀹炵幇浜烘棤闇鎿嶅績澧炲姞鍏抽敭璇嶆柟闈㈢殑浜嬪疁銆

         鏈夋暟鐧句竾绉嶅彲鑳界殑杈撳嚭鍙樺寲锛岃屼笉鏄竴绉嶃傝繖鏍凤紝灏变负瀵瑰厓鏁版嵁鏈変笉鍚岄渶姹傜殑搴旂敤绋嬪簭鎻愪緵浜嗘洿楂樼殑鐏垫椿鎬с

         鐢变簬鍏朵粬DBMS涔熼噰鐢ㄤ簡杩欑被鏂瑰紡锛岀Щ妞嶆洿涓哄鏄撱

鐒惰岋紝鐢变簬SHOW鍦∕ySQL鐨勯泧鍛樺拰鐢ㄦ埛涓崄鍒嗘祦琛岋紝濡傛灉SHOW娑堝け锛屽彲鑳戒細瀵艰嚧娣蜂贡锛屽洜姝や紶缁熺殑璇硶鏂瑰紡鏃犳硶缁欏嚭娑堥櫎SHOW鐨勮冻澶熺悊鐢便備簨瀹炰笂锛屽湪MySQL 5.1涓紝杩樺SHOW杩涜浜嗗椤瑰寮恒傚叧浜庤繖鏂归潰鐨勪粙缁嶏紝璇峰弬瑙23.2鑺傦紝鈥淪HOW璇彞鐨勬墿灞

鏍囧噯

鍦∕ySQL涓紝INFORMATION_SCHEMA琛ㄧ粨鏋勭殑瀹炴柦閬典粠ANSI/ISO SQL:2003鏍囧噯锛岀11閮ㄥ垎绾茶鈥濄傛垜浠殑鐩殑鍦ㄤ簬锛岃幏寰椾笌SQL:2003鏍稿績鐗规021鈥滃熀鏈俊鎭柟妗堚濈殑杩戜技鍏煎銆

SQL鏈嶅姟鍣2000锛堜篃閬典粠璇ユ爣鍑嗭級鐨勭敤鎴峰彲鑳藉凡娉ㄦ剰鍒板畠浠珮搴︾殑鐩镐技鎬с備絾鏄紝MySQL鐣ュ幓浜嗕笌鎴戜滑鐨勫疄鏂芥柟寮忎笉鐩稿叧鐨勪紬澶氬垪锛屽苟娣诲姞浜嗕竴浜汳ySQL鐗规湁鐨勫垪銆傚叾涓竴绉嶅垪灏辨槸INFORMATION_SCHEMA.TABLES琛ㄤ腑鐨勫紩鎿庡垪銆

灏界鍏朵粬DBMS浣跨敤浜嗕笉鍚岀殑鍚嶇О锛屽syscat鎴栫郴缁燂紝浣嗘爣鍑嗗悕绉版槸INFORMATION_SCHEMA

浜嬪疄涓婏紝灏界涓嶉渶瑕佺敓鎴愬悕涓INFORMATION_SCHEMA鐨勬枃浠讹紝鎴戜滑浠嶆彁渚涗簡鍚嶄负INFORMATION_SCHEMA鐨勬柊鏁版嵁搴撱鍙互浣跨敤USE璇彞灏INFORMATION_SCHEMA閫夋嫨涓洪粯璁ゆ暟鎹簱锛屼絾璁块棶璇ユ暟鎹簱涓墍鍚〃鐨勫敮涓鏂瑰紡鏄娇鐢⊿ELECT璇彞銆備笉鑳藉湪鍏朵腑鎻掑叆鍐呭锛屼笉鑳芥洿鏂板畠浠紝涔熶笉鑳藉垹闄ゅ叾涓殑鍐呭銆

鏉冮檺

褰撳墠鏉冮檺锛圫HOW锛夎姹傚拰SELCET鏉冮檺瑕佹眰涓嶅瓨鍦ㄥ樊鍒傚湪浠讳綍涓绉嶆儏鍐典笅锛岃鎯虫煡鐪嬪叧浜庡畠鐨勪俊鎭紝闇瑕佸鏌愮被瀵硅薄鎷ユ湁鐗瑰畾鏉冮檺銆

23.1.聽INFORMATION_SCHEMA琛

涓嬭堪绔犺妭璇存槑

鍦ㄤ笅闈㈢殑绔犺妭涓紝鎴戜滑閫夋嫨浜INFORMATION_SCHEMA涓殑琛ㄥ拰鍒椼傚浜庢瘡涓鍒楋紝鏈変笁绫讳俊鎭細

         鈥滄爣鍑嗗悕绉扳濓細鎸囨槑浜嗗垪鐨勬爣鍑哠QL鍚嶇О銆

         鈥淪HOW鍚嶇О鈥濓細鎸囨槑浜嗘渶杩慡HOW璇彞涓殑绛夋晥瀛楁鍚嶏紝濡傛灉鏈夌殑璇濄

         鈥滄敞閲娾濈粰鍑轰簡閫傜敤鐨勯檮鍔犱俊鎭

涓轰簡閬垮厤浣跨敤鏍囧噯鎴朌B2銆丼QL鏈嶅姟鍣ㄦ垨Oracle涓繚鐣欑殑鍚嶇О锛屾垜浠洿鏀逛簡鏍囨敞涓衡淪QL鎵╁睍鈥濈殑鍒楀悕銆傦紙渚嬪锛屽湪TABLES琛ㄤ腑锛屾垜浠皢COLLATION鏀逛负TABLE_COLLATION锛夈傝鍙傝鏈枃鏈熬澶勭粰鍑虹殑淇濈暀瀛楀垪琛ㄣhttp://www.dbazine.com/gulutzan5.shtml

瀛楃鍒楋紙渚嬪TABLES.TABLE_NAME锛夊畾涔夐氬父鏄VARCHAR(N) CHARACTER SET utf8锛屽叾涓紝N鑷冲皯涓64銆

鍦ㄦ瘡涓閮ㄥ垎涓紝鎸囨槑浜嗙瓑鏁堜簬浠INFORMATION_SCHEMA涓绱俊鎭殑SELECT璇彞鐨凷HOW璇彞锛屾垨鑰呬笉瀛樺湪杩欑被璇彞銆

娉ㄩ噴锛鐩墠锛屾湁涓浜涗涪澶辩殑鍒楀拰涓浜涙贩涔辩殑鍒椼傛垜浠鍦ㄧ潃鎵嬭В鍐宠闂锛屽苟闅忕潃鍙樺寲鎯呭喌鏇存柊鏂囨。銆

23.1.1. INFORMATION_SCHEMA SCHEMATA琛

璇ユ柟妗堟槸鏁版嵁搴擄紝鍥犳SCHEMATA琛ㄦ彁渚涗簡鍏充簬鏁版嵁搴撶殑淇℃伅銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

CATALOG_NAME

-

NULL

SCHEMA_NAME

 

Database

DEFAULT_CHARACTER_SET_NAME

 

 

DEFAULT_COLLATION_NAME

 

 

SQL_PATH

 

NULL

娉ㄩ噴锛SQL_PATH鍒楃殑涔嬫讳负NULL

涓嬭堪璇彞鏄瓑鏁堢殑锛

SELECT SCHEMA_NAME AS `Database
FROM INFORMATION_SCHEMA.SCHEMATA
[WHERE SCHEMA_NAME LIKE 'wild']
 
SHOW DATABASES
[LIKE 'wild']

23.1.2. INFORMATION_SCHEMA TABLES琛

TABLES琛ㄧ粰鍑轰簡鍏充簬鏁版嵁搴撲腑鐨勮〃鐨勪俊鎭

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

Table_...

 

TABLE_NAME

Table_...

 

TABLE_TYPE

 

 

ENGINE

Engine

MySQL鎵╁睍

VERSION

Version

MySQL鎵╁睍

ROW_FORMAT

Row_format

MySQL鎵╁睍

TABLE_ROWS

Rows

MySQL鎵╁睍

AVG_ROW_LENGTH

Avg_row_length

MySQL鎵╁睍

DATA_LENGTH

Data_length

MySQL鎵╁睍

MAX_DATA_LENGTH

Max_data_length

MySQL鎵╁睍

INDEX_LENGTH

Index_length

MySQL鎵╁睍

DATA_FREE

Data_free

MySQL鎵╁睍

AUTO_INCREMENT

Auto_increment

MySQL鎵╁睍

CREATE_TIME

Create_time

MySQL鎵╁睍

UPDATE_TIME

Update_time

MySQL鎵╁睍

CHECK_TIME

Check_time

MySQL鎵╁睍

TABLE_COLLATION

Collation

MySQL鎵╁睍

CHECKSUM

Checksum

MySQL鎵╁睍

CREATE_OPTIONS

Create_options

MySQL鎵╁睍

TABLE_COMMENT

Comment

MySQL鎵╁睍

娉ㄩ噴锛

         TABLE_SCHEMATABLE_NAMESHOW鏄剧ず涓殑鍗曚釜瀛楁锛屼緥濡俆able_in_db1

         TABLE_TYPE锛堣〃绫诲瀷锛夊簲鏄BASE TABLE锛堝熀鏈〃锛VIEW锛堣鍥撅級銆傚鏋滆〃鏄复鏃舵х殑锛TABLE_TYPE = TEMPORARY銆傦紙娌℃湁涓存椂瑙嗗浘锛屽洜姝わ紝鍥犳涓嶅瓨鍦ㄦ涔夛級銆

         濡傛灉琛ㄤ綅浜INFORMATION_SCHEMA鏁版嵁搴撲腑锛孴ABLE_ROWS鍒椾负NULL銆傚浜InnoDB琛紝鍦⊿QL浼樺寲涓紝琛岃鏁颁粎鏄ぇ姒備及璁″笺

         娌℃湁鍏充簬琛ㄩ粯璁ゅ瓧绗﹂泦鐨勪换浣曚俊鎭TABLE_COLLATION澶勪簬鍏抽棴鐘舵侊紝鍘熷洜鍦ㄤ簬鏍″鍚嶇О浠ュ瓧绗﹂泦鍚嶇О寮澶淬

涓嬭堪璇彞鏄瓑鏁堢殑锛

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']

23.1.3. INFORMATION_SCHEMA COLUMNS琛

COLUMNS琛ㄧ粰鍑轰簡琛ㄤ腑鐨勫垪淇℃伅銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

 

 

TABLE_NAME

 

 

COLUMN_NAME

Field

 

ORDINAL_POSITION

 

鍙傝娉ㄩ噴

COLUMN_DEFAULT

Default

 

IS_NULLABLE

Null

 

DATA_TYPE

Type

 

CHARACTER_MAXIMUM_LENGTH

Type

 

CHARACTER_OCTET_LENGTH

 

 

NUMERIC_PRECISION

Type

 

NUMERIC_SCALE

Type

 

CHARACTER_SET_NAME

 

 

COLLATION_NAME

Collation

 

COLUMN_TYPE

Type

MySQL鎵╁睍

COLUMN_KEY

Key

MySQL鎵╁睍

EXTRA

Extra

MySQL鎵╁睍

COLUMN_COMMENT

Comment

MySQL鎵╁睍

娉ㄩ噴锛

         SHOW涓紝绫诲瀷鏄剧ず鍖呮嫭鏉ヨ嚜鏁颁釜涓嶅悓COLUMNS鍒楃殑鍊笺

         ORDINAL_POSITION鏈夊繀瑕侊紝杩欐槸鍥犱负锛屼綘鍙兘浼氬湪鏌愪竴澶╅渶瑕ORDER BY ORDINAL_POSITION锛堟寜ORDINAL_POSITION鎺掑簭锛銆備笉鍚屼簬SHOW锛孲ELECT娌℃湁鑷姩鎺掑簭鍔熻兘銆

         CHARACTER_OCTET_LENGTH搴斾笌CHARACTER_MAXIMUM_LENGTH鐩稿悓锛屼絾澶氬瓧鑺傚瓧绗﹂泦闄ゅ銆

         CHARACTER_SET_NAME鍙敱Collation锛堟牎瀵癸級瀵煎嚭銆備緥濡傦紝濡傛灉缁欏嚭浜嗏SHOW FULL COLUMNS FROM t鈥濓紝鍦Collation锛堟牎瀵癸級鍒椾腑灏嗚鍒latin1_swedish_ci鐨勫硷紝瀛楃闆嗙敱绗1涓笅鍒掔嚎鍓嶇殑鍚嶇О鎸囨槑銆俵atin1.

涓嬭堪璇彞鏄瓑鏁堢殑锛

SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE table_name = 'tbl_name'
  [AND table_schema = 'db_name']
  [AND column_name LIKE 'wild']
 
SHOW COLUMNS
  FROM tbl_name
  [FROM db_name]
  [LIKE wild]

23.1.4. INFORMATION_SCHEMA STATISTICS琛

STATISTICS琛ㄧ粰鍑轰簡鍏充簬琛ㄧ储寮曠殑淇℃伅銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

 

锛濇暟鎹簱

TABLE_NAME

Table

 

NON_UNIQUE

Non_unique

 

INDEX_SCHEMA

 

锛濇暟鎹簱

INDEX_NAME

Key_name

 

SEQ_IN_INDEX

Seq_in_index

 

COLUMN_NAME

Column_name

 

COLLATION

Collation

 

CARDINALITY

Cardinality

 

SUB_PART

Sub_part

MySQL鎵╁睍

PACKED

Packed

MySQL鎵╁睍

NULLABLE

Null

MySQL鎵╁睍

INDEX_TYPE

Index_type

MySQL鎵╁睍

COMMENT

Comment

MySQL鎵╁睍

娉ㄩ噴锛

         娌℃湁鍏充簬杩欎簺绱㈠紩鐨勬爣鍑嗚〃銆備笂闈㈢殑鍒楄〃涓嶴QL鏈嶅姟鍣2000涓sp_statistics杩斿洖鐨勫肩被浼笺備笉鍚屼箣澶勫湪浜庣敤CATALOG鏇挎崲浜哘UALIFIER锛屽苟鐢⊿CHEMA鏇挎崲浜哋WNER銆

鏄捐屾槗瑙侊紝鍓嶈堪琛ㄥ拰SHOW INDEX鐨勮緭鍑哄潎鏄敱鐩稿悓鐨勭埗瀵硅薄瀵煎嚭鐨勩鍥犳锛岀浉鍏虫у凡鍏抽棴銆

涓嬭堪璇彞鏄瓑鏁堢殑锛

SELECT * FROM INFORMATION_SCHEMA.STATISTICS
  WHERE table_name = 'tbl_name'
  [AND table_schema = 'db_name']
 
SHOW INDEX
  FROM tbl_name
  [FROM db_name]

23.1.5. INFORMATION_SCHEMA USER_PRIVILEGES琛

USER_PRIVILEGES锛堢敤鎴锋潈闄愶級琛ㄧ粰鍑轰簡鍏充簬鍏ㄧ▼鏉冮檺鐨勪俊鎭璇ヤ俊鎭簮鑷mysql.user鎺堟潈琛ㄣ

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

GRANTEE

 

渚嬪鈥渦ser'@'host鈥

TABLE_CATALOG

 

NULL

PRIVILEGE_TYPE

 

 

IS_GRANTABLE

 

 

娉ㄩ噴锛

         杩欐槸涓涓潪鏍囧噯琛ㄣ傚叾鍊兼潵鑷mysql.user琛ㄣ

23.1.6. INFORMATION_SCHEMA SCHEMA_PRIVILEGES琛

SCHEMA_PRIVILEGES锛堟柟妗堟潈闄愶級琛ㄧ粰鍑轰簡鍏充簬鏂规锛堟暟鎹簱锛夋潈闄愮殑淇℃伅銆傝淇℃伅鏉ヨ嚜mysql.db鎺堟潈琛ㄣ

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

GRANTEE

 

渚嬪鈥渦ser'@'host鈥

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

 

 

PRIVILEGE_TYPE

 

 

IS_GRANTABLE

 

 

娉ㄩ噴锛

         杩欐槸涓涓潪鏍囧噯琛ㄣ傚叾鍊兼潵鑷mysql.db琛ㄣ

23.1.7. INFORMATION_SCHEMA TABLE_PRIVILEGES琛

TABLE_PRIVILEGES锛堣〃鏉冮檺锛琛ㄧ粰鍑轰簡鍏充簬琛ㄦ潈闄愮殑淇℃伅銆傝淇℃伅婧愯嚜mysql.tables_priv鎺堟潈琛ㄣ

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

GRANTEE

 

渚嬪鈥渦ser'@'host鈥

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

 

 

TABLE_NAME

 

 

PRIVILEGE_TYPE

 

 

IS_GRANTABLE

 

 

涓嬭堪璇彞涓嶇瓑鏁堬細

SELECT ... FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES
 
SHOW GRANTS ...

PRIVILEGE_TYPE鍙互鍖呭惈杩欎簺鍊间箣涓锛堜粎鑳戒竴涓級锛SELECTINSERTUPDATEREFERENCESALTERINDEXDROP銆丆REATE VIEW

23.1.8. INFORMATION_SCHEMA COLUMN_PRIVILEGES琛

COLUMN_PRIVILEGES锛堝垪鏉冮檺锛夎〃缁欏嚭浜嗗叧浜庡垪鏉冮檺鐨勪俊鎭傝淇℃伅婧愯嚜mysql.columns_priv鎺堟潈琛ㄣ

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

GRANTEE

 

渚嬪鈥渦ser'@'host鈥

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

 

 

TABLE_NAME

 

 

COLUMN_NAME

 

 

PRIVILEGE_TYPE

 

 

IS_GRANTABLE

 

 

娉ㄩ噴锛

         SHOW FULL COLUMNS锛堟樉绀哄畬鏁村垪锛夌殑杈撳嚭涓紝鏉冮檺鍊间綅浜庝竴涓瓧娈靛苟閲囩敤灏忓啓褰㈠紡锛屼緥濡俿elect銆乮nsert銆乽pdate銆乺eferences銆COLUMN_PRIVILEGES涓紝姣忕鏉冮檺鍗犱竴琛岋紝骞朵负澶у啓褰㈠紡銆

         PRIVILEGE_TYPE鍙互鍖呭惈杩欎簺鍊间箣涓锛堜粎鑳戒竴涓級锛SELECT, INSERT, UPDATE, REFERENCES.

         濡傛灉鐢ㄦ埛鏈GRANT OPTION鏉冮檺锛閭d箞IS_GRANTABLE搴斾负YES銆傚惁鍒欙紝IS_GRANTABLE搴斾负NO銆傚湪杈撳嚭涓紝涓嶄細灏咷RANT OPTION浣滀负鍗曠嫭鏉冮檺鍒楀嚭銆

涓嬭堪璇彞涓嶇瓑鏁堬細

SELECT ... FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES
 
SHOW GRANTS ...

23.1.9. INFORMATION_SCHEMA CHARACTER_SETS琛

CHARACTER_SETS锛堝瓧绗﹂泦锛夎〃鎻愪緵浜嗗叧浜庡彲鐢ㄥ瓧绗﹂泦鐨勪俊鎭

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

CHARACTER_SET_NAME

Charset

 

DEFAULT_COLLATE_NAME

Default collation

 

DESCRIPION

Description

MySQL鎵╁睍

MAXLEN

Maxlen

MySQL鎵╁睍

娉ㄩ噴锛

         鎴戜滑澧炲姞浜嗕袱涓潪鏍囧噯鍒楋紝鍒嗗埆瀵瑰簲浜SHOW CHARACTER SET杈撳嚭鐨凞escription锛堟弿杩帮級鍜孧axlen锛堟渶澶ч暱搴︼級鍒

涓嬭堪璇彞鏄瓑鏁堢殑锛

SELECT * FROM INFORMATION_SCHEMA.CHARACTER_SETS
  [WHERE name LIKE 'wild']
 
SHOW CHARACTER SET
  [LIKE 'wild']

23.1.10. INFORMATION_SCHEMA COLLATIONS琛

COLLATIONS琛ㄦ彁渚涗簡鍏充簬鍚勫瓧绗﹂泦鐨勫鐓т俊鎭

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

COLLATION_NAME

Collation

 

娉ㄩ噴锛

         鎴戜滑澧炲姞浜5涓潪鏍囧噯鍒楋紝鍒嗗埆瀵瑰簲浜SHOW COLLATION杈撳嚭鐨凜harsetIdDefaultCompiledSortlen鍒

涓嬭堪璇彞鏄瓑鏁堢殑锛

SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
  [WHERE collation_name LIKE 'wild']
 
SHOW COLLATION
  [LIKE 'wild']

23.1.11. INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY琛

COLLATION_CHARACTER_SET_APPLICABILITY琛ㄦ寚鏄庝簡鍙敤浜庢牎瀵圭殑瀛楃闆嗐傝繖浜涘垪绛夋晥浜SHOW COLLATION鐨勫墠涓や釜鏄剧ず瀛楁銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

COLLATION_NAME

Collation

 

CHARACTER_SET_NAME

Charset

 

23.1.12. INFORMATION_SCHEMA TABLE_CONSTRAINTS琛

TABLE_CONSTRAINTS琛ㄦ弿杩颁簡瀛樺湪绾︽潫鐨勮〃銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

CONSTRAINT_CATALOG

 

NULL

CONSTRAINT_SCHEMA

 

 

CONSTRAINT_NAME

 

 

TABLE_SCHEMA

 

 

TABLE_NAME

 

 

CONSTRAINT_TYPE

 

 

娉ㄩ噴锛

         CONSTRAINT_TYPE鐨勫煎彲浠ユ槸UNIQUE锛堝敮涓锛PRIMARY KEY锛堜富閿級FOREIGN KEY锛堝閿級銆

         Non_unique瀛楁涓0鏃讹紝UNIQUEPRIMARY KEY淇℃伅涓嶴HOW INDEX杈撳嚭鐨凨ey_name瀛楁涓粰鍑虹殑淇℃伅鍩烘湰鐩稿悓銆

         CONSTRAINT_TYPE鍒楀彲鍖呭惈涓嬭堪鍊间箣涓锛UNIQUEPRIMARY KEYFOREIGN KEYCHECK銆傝繖鏄竴涓狢HAR锛堥潪ENUM锛夊垪銆鍦ㄦ垜浠敮鎸丆HECK鍓嶏紝CHECK鍊间笉鍙敤銆

23.1.13. INFORMATION_SCHEMA KEY_COLUMN_USAGE琛

KEY_COLUMN_USAGE琛ㄦ弿杩颁簡鍏锋湁绾︽潫鐨勯敭鍒椼

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

CONSTRAINT_CATALOG

 

NULL

CONSTRAINT_SCHEMA

 

 

CONSTRAINT_NAME

 

 

TABLE_CATALOG

 

 

TABLE_SCHEMA

 

 

TABLE_NAME

 

 

COLUMN_NAME

 

 

ORDINAL_POSITION

 

 

POSITION_IN_UNIQUE_CONSTRAINT

 

 

REFERENCED_TABLE_SCHEMA

 

 

REFERENCED_TABLE_NAME

 

 

REFERENCED_COLUMN_NAME

 

 

娉ㄩ噴锛

         濡傛灉绾︽潫涓哄閿紝杩欏氨鏄閿垪锛岃屼笉鏄閿紩鐢ㄧ殑鍒椼

         ORDINAL_POSITION鐨勫兼槸鍒楀湪绾︽潫涓殑浣嶇疆锛岃屼笉鏄垪鍦ㄨ〃涓殑浣嶇疆銆鍒椾綅缃噰鐢ㄤ粠1寮濮嬬殑鏁板肩紪鍙枫

         瀵逛簬鈥滃敮涓鈥濆拰鈥滀富閿濈害鏉燂紝POSITION_IN_UNIQUE_CONSTRAINT鐨勫间负NULL銆瀵逛簬鈥滃閿濈害鏉燂紝瀹冩槸鎵寮曠敤琛ㄥ唴閿腑鐨勯『搴忎綅缃

渚嬪锛屽亣瀹氭湁涓や釜鍏锋湁涓嬭堪瀹氫箟鐨勮〃t1鍜宼3锛

CREATE TABLE t1
(
s1 INT,
s2 INT,
s3 INT,
PRIMARY KEY(s3)
) ENGINE=InnoDB;
 
CREATE TABLE t3
(
s1 INT,
s2 INT,
s3 INT,
KEY(s1),
CONSTRAINT CO FOREIGN KEY (s2) REFERENCES t1(s3)
) ENGINE=InnoDB;

瀵逛簬杩欎袱涓〃锛KEY_COLUMN_USAGE琛ㄦ湁涓よ锛

o        涓琛屽惈鏈CONSTRAINT_NAME='PRIMARY', TABLE_NAME='t1', COLUMN_NAME='s3', ORDINAL_POSITION=1, POSITION_IN_UNIQUE_CONSTRAINT=NULL銆

o        鍙︿竴琛屽惈鏈CONSTRAINT_NAME='CO', TABLE_NAME='t3', COLUMN_NAME='s2', ORDINAL_POSITION=1, POSITION_IN_UNIQUE_CONSTRAINT=1銆

23.1.14. INFORMATION_SCHEMA ROUTINES琛

ROUTINES琛ㄦ彁渚涗簡鍏充簬瀛樺偍瀛愮▼搴忥紙瀛樺偍绋嬪簭鍜屽嚱鏁帮級鐨勪俊鎭姝ゆ椂锛ROUTINES琛ㄤ笉鍖呭惈鑷畾涔鍑芥暟锛圲DF锛夈

鍚嶄负鈥mysql.proc name鈥濈殑鍒楁寚鏄庝簡瀵瑰簲浜INFORMATION_SCHEMA.ROUTINES琛ㄧ殑mysql.proc琛ㄥ垪锛屽鏋滄湁鐨勮瘽銆

鏍囧噯鍚嶇О

mysql.proc

娉ㄩ噴

SPECIFIC_NAME

specific_name

 

ROUTINE_CATALOG

 

NULL

ROUTINE_SCHEMA

db

 

ROUTINE_NAME

name

 

ROUTINE_TYPE

type

{PROCEDURE|FUNCTION}

DTD_IDENTIFIER

 

锛堟暟鎹被鍨嬫弿杩扮锛

ROUTINE_BODY

 

SQL

ROUTINE_DEFINITION

body

 

EXTERNAL_NAME

 

NULL

EXTERNAL_LANGUAGE

language

NULL

PARAMETER_STYLE

 

SQL

IS_DETERMINISTIC

is_deterministic

 

SQL_DATA_ACCESS

sql_data_access

 

SQL_PATH

 

NULL

SECURITY_TYPE

security_type

 

CREATED

created

 

LAST_ALTERED

modified

 

SQL_MODE

sql_mode

MySQL鎵╁睍

ROUTINE_COMMENT

comment

MySQL鎵╁睍

DEFINER

definer

MySQL鎵╁睍

娉ㄩ噴锛

         MySQL璁$畻EXTERNAL_LANGUAGE锛屽洜姝わ細

o        濡傛灉mysql.proc.language='SQL'锛岄偅涔EXTERNAL_LANGUAGENULL

o        鍚﹀垯锛EXTERNAL_LANGUAGEmysql.proc.language涓殑鍊銆傜劧鑰岋紝鐢变簬灏氭病鏈夊閮ㄨ瑷锛屽洜姝よ鍊兼讳负NULL

23.1.15. INFORMATION_SCHEMA VIEWS琛

VIEWS琛ㄧ粰鍑轰簡鍏充簬鏁版嵁搴撲腑鐨勮鍥剧殑淇℃伅銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

TABLE_CATALOG

 

NULL

TABLE_SCHEMA

 

 

TABLE_NAME

 

 

VIEW_DEFINITION

 

 

CHECK_OPTION

 

 

IS_UPDATABLE

 

 

DEFINER

 

 

SECURITY_TYPE

 

 

娉ㄩ噴锛

         鏈変竴绉嶆柊鐨勬潈闄SHOW VIEW锛屽鏋滄病鏈夊畠锛屽皢鏃犳硶鐪嬪埌VIEWS琛ㄣ

         VIEW_DEFINITION鍒楀惈鏈変綘鍦⊿HOW CREATE VIEW鎵鐢熸垚鐨凜reate Table瀛楁涓鍒扮殑澶у鏁颁俊鎭璺宠繃SELECT鍓嶇殑鍗曡瘝锛屽苟璺宠繃鍏锋湁CHECK OPTION锛堟鏌ラ夐」锛夌殑鍗曡瘝銆備緥濡傦紝濡傛灉鍒濆璇彞鏄細

                CREATE VIEW v AS
                  SELECT s2,s1 FROM t
                  WHERE s1 > 5
                  ORDER BY s1
                  WITH CHECK OPTION;

閭d箞瑙嗗浘瀹氫箟涓猴細

SELECT s2,s1 FROM t WHERE s1 > 5 ORDER BY s1

         CHECK_OPTION鍒楃殑鍊兼讳负NONE

         濡傛灉瑙嗗浘鏄彲鏇存柊鐨勶紝IS_UPDATABLE鍒楃殑鍊间负YES锛屽鏋瑙嗗浘鏄笉鍙洿鏂扮殑锛IS_UPDATABLE鍒楃殑鍊间负NO銆

         DEFINER鍒楁寚鏄庝簡瀹氫箟瑙嗗浘鐨勪汉SECURITY_TYPE鐨勫间负DEFINERINVOKER

23.1.16. INFORMATION_SCHEMA TRIGGERS琛

TRIGGERS琛ㄦ彁渚涗簡鍏充簬瑙﹀彂绋嬪簭鐨勪俊鎭

蹇呴』鏈SUPER鏉冮檺鎵嶈兘鏌ョ湅璇ヨ〃銆

鏍囧噯鍚嶇О

SHOW鍚嶇О

娉ㄩ噴

TRIGGER_CATALOG

 

NULL

TRIGGER_SCHEMA

 

 

TRIGGER_NAME

Trigger

 

EVENT_MANIPULATION

Event

 

EVENT_OBJECT_CATALOG

 

NULL

EVENT_OBJECT_SCHEMA

 

 

EVENT_OBJECT_TABLE

Table

 

ACTION_ORDER

 

0

ACTION_CONDITION

 

NULL

ACTION_STATEMENT

Statement

 

ACTION_ORIENTATION

 

ROW

ACTION_TIMING

Timing

 

ACTION_REFERENCE_OLD_TABLE

 

NULL

ACTION_REFERENCE_NEW_TABLE

 

NULL

ACTION_REFERENCE_OLD_ROW

 

OLD

ACTION_REFERENCE_NEW_ROW

 

NEW

CREATED

 

NULL (0)

SQL_MODE

 

 

娉ㄩ噴锛

         TRIGGER_SCHEMATRIGGER_NAME鍒椾腑鍒嗗埆鍚湁鐩稿簲鏁版嵁搴撶殑鍚嶇О浠ュ強瑙﹀彂绋嬪簭鐨勫悕绉帮紝鍦ㄨ鏁版嵁搴撲腑锛屽惈鏈夎瑙﹀彂绋嬪簭銆

         EVENT_MANIPULATION鍒楀惈鏈変笅杩板间箣涓锛INSERT銆丏ELETE銆佹垨UPDATE銆

         姝e绗21绔狅細瑙﹀彂绋嬪簭涓寚鍑虹殑閭f牱锛屾瘡涓Е鍙戠▼搴忓潎涓庝竴涓〃鍑嗙‘鐩稿叧銆EVENT_OBJECT_SCHEMAEVENT_OBJECT_TABLE鍒楀寘鍚浉搴旂殑鏁版嵁搴撳拰琛ㄥ悕锛屽湪璇ユ暟鎹簱涓紝鍚湁璇ヨ〃銆

         ACTION_ORDER璇彞鍚湁瑙﹀彂绋嬪簭鍔ㄤ綔锛堝湪鐩稿悓琛ㄤ笂鎵鏈夌被浼艰Е鍙戠▼搴忓垪琛ㄤ腑锛夌殑椤哄簭浣嶇疆銆傜洰鍓嶈鍊兼讳负0锛岃繖鏄洜涓哄湪鐩稿悓琛ㄤ笂鍏锋湁鐩稿悓EVENT_MANIPULATIONACTION_TIMING鐨勮Е鍙戠▼搴忎笉鑳借秴杩1涓

         ACTION_STATEMENT鍒楀惈鏈夋縺娲讳簡瑙﹀彂绋嬪簭鏃跺皢瑕佹墽琛岀殑璇彞銆杩欎笌SHOW TRIGGERS杈撳嚭鐨凷tatement锛堣鍙ワ級鍒椾腑鏄剧ず鐨勬枃鏈浉鍚屻娉ㄦ剰锛岃鏂囨湰閲囩敤浜哢TF-8缂栫爜鏂瑰紡銆

         ACTION_ORIENTATION鍒楁诲惈鏈夊尖ROW

         ACTION_TIMING鍒楀惈鏈変笅杩颁袱绉嶅间箣涓锛BEFOREAFTER

         ACTION_REFERENCE_OLD_ROWACTION_REFERENCE_NEW_ROW鍒嗗埆鍚湁鏃х殑鍜屾柊鐨勫垪鏍囪瘑绗銆傝繖鎰忓懗鐫ACTION_REFERENCE_OLD_ROW鎬诲惈鏈夊尖OLD锛孉CTION_REFERENCE_NEW_ROW鎬诲惈鏈夊尖NEW

         SQL_MODE鍒楁樉绀轰簡鍒涘缓瑙﹀彂绋嬪簭鏃舵湁鏁堢殑鏈嶅姟鍣⊿QL妯″紡锛堟棤璁哄綋鍓嶇殑鏈嶅姟鍣⊿QL妯″紡涓轰綍锛屽彧瑕佹縺娲讳簡瑙﹀彂绋嬪簭锛屽畠灏嗕繚鎸佹湁鏁堬級銆傝鍒楃殑鍙兘鍙栧艰寖鍥翠笌sql_mode绯荤粺鍙橀噺鐨勫彇鍊艰寖鍥寸浉鍚屻傝鍙傝5.3.2鑺傦紝鈥淪QL鏈嶅姟鍣ㄦā寮忊

         鍦ㄤ笅杩板垪涓紝鐩墠鎬诲惈鏈塏ULL锛TRIGGER_CATALOGEVENT_OBJECT_CATALOGACTION_CONDITIONACTION_REFERENCE_OLD_TABLEACTION_REFERENCE_NEW_TABLECREATED

渚嬪锛屼娇鐢21.3鑺傦紝鈥滀娇鐢ㄨЕ鍙戠▼搴忊涓畾涔夌殑瑙﹀彂绋嬪簭ins_sum銆

mysql> SELECT * FROM INFORMATION_SCHEMA.TRIGGERS\G
*************************** 1. row ***************************
 TRIGGER_CATALOG: NULL
TRIGGER_SCHEMA: test
 TRIGGER_NAME: ins_sum
  EVENT_MANIPULATION: INSERT
EVENT_OBJECT_CATALOG: NULL
 EVENT_OBJECT_SCHEMA: test
  EVENT_OBJECT_TABLE: account
 ACTION_ORDER: 0
ACTION_CONDITION: NULL
ACTION_STATEMENT:  SET @sum = @sum + NEW.amount
  ACTION_ORIENTATION: ROW
 ACTION_TIMING: BEFORE
ACTION_REFERENCE_OLD_TABLE: NULL
ACTION_REFERENCE_NEW_TABLE: NULL
  ACTION_REFERENCE_OLD_ROW: OLD
  ACTION_REFERENCE_NEW_ROW: NEW
CREATED: NULL
1 row in set (1.54 sec)

鍙﹁鍙傝13.5.4.20鑺傦紝鈥淪HOW TRIGGERS璇硶鈥

23.1.17. 鍏朵粬INFORMATION_SCHEMA琛

鎴戜滑鎵撶畻瀹炴柦闄勫姞鐨INFORMATION_SCHEMA琛ㄣ傚挨鍏舵槸锛屾垜浠‘璁や簡瀵INFORMATION_SCHEMA.PARAMETERSINFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS鐨勯渶姹傘

23.2. SHOW璇彞鐨勬墿灞

鏌愪簺SHOW璇彞鐨勬墿灞曚即闅忕潃INFORMATION_SCHEMA鐨勫疄鏂斤細

         SHOW鍙敤浜庤幏鍙栧叧浜嶪NFORMATION_SCHEMA鏈韩缁撴瀯鐨勪俊鎭

         涓浜SHOW璇彞鍏佽浣跨敤WHERE瀛愬彞锛岃繖鏍凤紝鍦ㄦ寚瀹氶渶瑕佹樉绀虹殑琛屾椂锛屽彲鏇翠负鐏垫椿銆

INFORMATION_SCHEMA鏄竴绉嶄俊鎭暟鎹簱锛屽洜姝わ紝鍦SHOW DATABASES鐨勮緭鍑轰腑锛屽寘鍚叾鍚嶇О銆備笌姝ょ被浼硷紝SHOW TABLES鍙笌INFORMATION_SCHEMA涓璧蜂娇鐢紝浠ヨ幏鍙栬〃娓呭崟銆

mysql> SHOW TABLES FROM INFORMATION_SCHEMA;
+---------------------------------------+
| Tables_in_information_schema|
+---------------------------------------+
| SCHEMATA|
| TABLES|
| COLUMNS |
| CHARACTER_SETS |
| COLLATIONS  |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| ROUTINES|
| STATISTICS  |
| VIEWS |
| TRIGGERS|
| USER_PRIVILEGES|
| SCHEMA_PRIVILEGES  |
| TABLE_PRIVILEGES|
| COLUMN_PRIVILEGES  |
| TABLE_CONSTRAINTS  |
| KEY_COLUMN_USAGE|
+---------------------------------------+

SHOW COLUMNSDESCRIBE鑳藉鏄剧ず鍗曠嫭INFORMATION_SCHEMA琛ㄤ腑鐨勫垪淇℃伅銆

鎵╁睍浜嗕竴浜SHOW璇彞锛屽厑璁镐娇鐢╓HERE瀛愬彞锛

SHOW CHARACTER SET
SHOW COLLATION
SHOW COLUMNS
SHOW DATABASES
SHOW FUNCTION STATUS
SHOW KEYS
SHOW OPEN TABLES
SHOW PROCEDURE STATUS
SHOW STATUS
SHOW TABLE STATUS
SHOW TABLES
SHOW VARIABLES

濡傛灉鏈WHERE瀛愬彞鐨勮瘽锛屽皢鏍规嵁SHOW璇彞鏄剧ず鐨勫垪鍚嶈繘琛岃绠椼渚嬪锛SHOW COLLATION璇彞鍙骇鐢熻繖浜涜緭鍑哄垪

渚嬪锛SHOW CHARACTER SET璇彞鍙骇鐢熻繖浜涜緭鍑哄垪

mysql> SHOW CHARACTER SET;
Charset
鎻忚堪
榛樿鏍″
鏈澶ч暱搴
 big5 
 Big5 Traditional Chinese
 big5_chinese_ci 
2 
 dec8 
 DEC West European 
 dec8_swedish_ci 
1 
 cp850
 DOS West European 
 cp850_general_ci
1 
 hp8
 HP West European
 hp8_english_ci
1 
 koi8r
 KOI8-R Relcom Russian 
 koi8r_general_ci
1 
 latin1
 cp1252 West European  
 latin1_swedish_ci
1 
 latin2
 ISO 8859-2 Central European 
 latin2_general_ci
1 
 

瑕佹兂涓SHOW CHARACTER SET涓璧蜂娇鐢╓HERE瀛愬彞锛屽簲寮曠敤杩欎簺鍒楀悕绉銆備緥濡傦紝鍦ㄤ笅闈㈢殑璇彞涓紝缁欏嚭浜嗙敤浜庨粯璁ゆ牎瀵逛笖鍚湁瀛楃涓测japanese鈥濈殑瀛楃闆嗙殑淇℃伅锛

mysql> SHOW CHARACTER SET WHERE `Default collation` LIKE '%japanese%';
 Charset 
 鎻忚堪 
榛樿鏍″
鏈澶ч暱搴
 ujis
 EUC-JP Japanese 
 ujis_japanese_ci
3 
 sjis
 Shift-JIS Japanese  
 sjis_japanese_ci
2 
 cp932
 SJIS for Windows Japanese 
 cp932_japanese_ci
2 
 eucjpms 
 UJIS for Windows Japanese 
 eucjpms_japanese_ci 
3 

璇ヨ鍙ユ樉绀轰簡澶氬瓧鑺傚瓧绗﹂泦銆

mysql> SHOW CHARACTER SET WHERE Maxlen > 1;
 Charset 
 鎻忚堪  
榛樿鏍″
鏈澶ч暱搴
 big5
 Big5 Traditional Chinese  
 big5_chinese_ci 
2 
 ujis
 EUC-JP Japanese
 ujis_japanese_ci
3 
 sjis
 Shift-JIS Japanese  
 sjis_japanese_ci
2 
 euckr
 EUC-KR Korean 
 euckr_korean_ci 
2 
 gb2312  
 GB2312 Simplified Chinese 
 gb2312_chinese_ci
2 
 gbk 
 GBK Simplified Chinese
 gbk_chinese_ci
2 
 utf8
 UTF-8 Unicode 
 utf8_general_ci 
3 
 ucs2
 UCS-2 Unicode 
 ucs2_general_ci 
2 
 cp932
 SJIS for Windows Japanese 
 cp932_japanese_ci
2 
 eucjpms 
 UJIS for Windows Japanese 
 eucjpms_japanese_ci 
3 
 

杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com銆傚師濮嬪弬鑰冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆