鐩綍
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 DATABASES銆SHOW 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鏉冮檺瑕佹眰涓嶅瓨鍦ㄥ樊鍒傚湪浠讳綍涓绉嶆儏鍐典笅锛岃鎯虫煡鐪嬪叧浜庡畠鐨勪俊鎭紝闇瑕佸鏌愮被瀵硅薄鎷ユ湁鐗瑰畾鏉冮檺銆
涓嬭堪绔犺妭璇存槑
鍦ㄤ笅闈㈢殑绔犺妭涓紝鎴戜滑閫夋嫨浜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璇彞锛屾垨鑰呬笉瀛樺湪杩欑被璇彞銆
娉ㄩ噴锛鐩墠锛屾湁涓浜涗涪澶辩殑鍒楀拰涓浜涙贩涔辩殑鍒椼傛垜浠鍦ㄧ潃鎵嬭В鍐宠闂锛屽苟闅忕潃鍙樺寲鎯呭喌鏇存柊鏂囨。銆
璇ユ柟妗堟槸鏁版嵁搴擄紝鍥犳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']
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_SCHEMA鍜TABLE_NAME鏄SHOW鏄剧ず涓殑鍗曚釜瀛楁锛屼緥濡俆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']
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]
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]
USER_PRIVILEGES锛堢敤鎴锋潈闄愶級琛ㄧ粰鍑轰簡鍏充簬鍏ㄧ▼鏉冮檺鐨勪俊鎭璇ヤ俊鎭簮鑷mysql.user鎺堟潈琛ㄣ
鏍囧噯鍚嶇О |
SHOW鍚嶇О |
娉ㄩ噴 |
GRANTEE |
|
渚嬪鈥渦ser'@'host鈥 |
TABLE_CATALOG |
|
NULL |
PRIVILEGE_TYPE |
|
|
IS_GRANTABLE |
|
|
娉ㄩ噴锛
路 杩欐槸涓涓潪鏍囧噯琛ㄣ傚叾鍊兼潵鑷mysql.user琛ㄣ
SCHEMA_PRIVILEGES锛堟柟妗堟潈闄愶級琛ㄧ粰鍑轰簡鍏充簬鏂规锛堟暟鎹簱锛夋潈闄愮殑淇℃伅銆傝淇℃伅鏉ヨ嚜mysql.db鎺堟潈琛ㄣ
鏍囧噯鍚嶇О |
SHOW鍚嶇О |
娉ㄩ噴 |
GRANTEE |
|
渚嬪鈥渦ser'@'host鈥 |
TABLE_CATALOG |
|
NULL |
TABLE_SCHEMA |
|
|
PRIVILEGE_TYPE |
|
|
IS_GRANTABLE |
|
|
娉ㄩ噴锛
路 杩欐槸涓涓潪鏍囧噯琛ㄣ傚叾鍊兼潵鑷mysql.db琛ㄣ
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鍙互鍖呭惈杩欎簺鍊间箣涓锛堜粎鑳戒竴涓級锛SELECT銆INSERT銆UPDATE銆REFERENCES銆ALTER銆INDEX銆DROP銆丆REATE VIEW銆
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 ...
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']
COLLATIONS琛ㄦ彁渚涗簡鍏充簬鍚勫瓧绗﹂泦鐨勫鐓т俊鎭
鏍囧噯鍚嶇О |
SHOW鍚嶇О |
娉ㄩ噴 |
COLLATION_NAME |
Collation |
|
娉ㄩ噴锛
路 鎴戜滑澧炲姞浜5涓潪鏍囧噯鍒楋紝鍒嗗埆瀵瑰簲浜SHOW COLLATION杈撳嚭鐨凜harset銆Id銆Default銆Compiled鍜Sortlen鍒銆
涓嬭堪璇彞鏄瓑鏁堢殑锛
SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
[WHERE collation_name LIKE 'wild']
SHOW COLLATION
[LIKE 'wild']
COLLATION_CHARACTER_SET_APPLICABILITY琛ㄦ寚鏄庝簡鍙敤浜庢牎瀵圭殑瀛楃闆嗐傝繖浜涘垪绛夋晥浜SHOW COLLATION鐨勫墠涓や釜鏄剧ず瀛楁銆
鏍囧噯鍚嶇О |
SHOW鍚嶇О |
娉ㄩ噴 |
COLLATION_NAME |
Collation |
|
CHARACTER_SET_NAME |
Charset |
|
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鏃讹紝UNIQUE鍜PRIMARY KEY淇℃伅涓嶴HOW INDEX杈撳嚭鐨凨ey_name瀛楁涓粰鍑虹殑淇℃伅鍩烘湰鐩稿悓銆
路 CONSTRAINT_TYPE鍒楀彲鍖呭惈涓嬭堪鍊间箣涓锛UNIQUE銆PRIMARY KEY銆FOREIGN KEY銆CHECK銆傝繖鏄竴涓狢HAR锛堥潪ENUM锛夊垪銆鍦ㄦ垜浠敮鎸丆HECK鍓嶏紝CHECK鍊间笉鍙敤銆
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銆
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_LANGUAGE涓NULL銆
o 鍚﹀垯锛EXTERNAL_LANGUAGE涓mysql.proc.language涓殑鍊銆傜劧鑰岋紝鐢变簬灏氭病鏈夊閮ㄨ瑷锛屽洜姝よ鍊兼讳负NULL銆
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鐨勫间负DEFINER鎴INVOKER銆
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_SCHEMA鍜TRIGGER_NAME鍒椾腑鍒嗗埆鍚湁鐩稿簲鏁版嵁搴撶殑鍚嶇О浠ュ強瑙﹀彂绋嬪簭鐨勫悕绉帮紝鍦ㄨ鏁版嵁搴撲腑锛屽惈鏈夎瑙﹀彂绋嬪簭銆
路 EVENT_MANIPULATION鍒楀惈鏈変笅杩板间箣涓锛INSERT銆丏ELETE銆佹垨UPDATE銆
路 姝e绗21绔狅細瑙﹀彂绋嬪簭涓寚鍑虹殑閭f牱锛屾瘡涓Е鍙戠▼搴忓潎涓庝竴涓〃鍑嗙‘鐩稿叧銆EVENT_OBJECT_SCHEMA鍜EVENT_OBJECT_TABLE鍒楀寘鍚浉搴旂殑鏁版嵁搴撳拰琛ㄥ悕锛屽湪璇ユ暟鎹簱涓紝鍚湁璇ヨ〃銆
路 ACTION_ORDER璇彞鍚湁瑙﹀彂绋嬪簭鍔ㄤ綔锛堝湪鐩稿悓琛ㄤ笂鎵鏈夌被浼艰Е鍙戠▼搴忓垪琛ㄤ腑锛夌殑椤哄簭浣嶇疆銆傜洰鍓嶈鍊兼讳负0锛岃繖鏄洜涓哄湪鐩稿悓琛ㄤ笂鍏锋湁鐩稿悓EVENT_MANIPULATION鍜ACTION_TIMING鐨勮Е鍙戠▼搴忎笉鑳借秴杩1涓
路 ACTION_STATEMENT鍒楀惈鏈夋縺娲讳簡瑙﹀彂绋嬪簭鏃跺皢瑕佹墽琛岀殑璇彞銆杩欎笌SHOW TRIGGERS杈撳嚭鐨凷tatement锛堣鍙ワ級鍒椾腑鏄剧ず鐨勬枃鏈浉鍚屻娉ㄦ剰锛岃鏂囨湰閲囩敤浜哢TF-8缂栫爜鏂瑰紡銆
路 ACTION_ORIENTATION鍒楁诲惈鏈夊尖ROW鈥銆
路 ACTION_TIMING鍒楀惈鏈変笅杩颁袱绉嶅间箣涓锛鈥BEFORE鈥鎴鈥AFTER鈥銆
路 鍒ACTION_REFERENCE_OLD_ROW鍜ACTION_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_CATALOG锛EVENT_OBJECT_CATALOG锛ACTION_CONDITION锛ACTION_REFERENCE_OLD_TABLE锛ACTION_REFERENCE_NEW_TABLE鍜CREATED銆
渚嬪锛屼娇鐢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)
鏌愪簺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 COLUMNS鍜DESCRIBE鑳藉鏄剧ず鍗曠嫭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銆傚師濮嬪弬鑰冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆