鐩綍
璇ヨ妭鎻忚堪浜嗗浣曞湪MySQL涓啓鏂囧瓧鍊笺傚寘鎷瓧绗︿覆銆佹暟鍊笺佸崄鍏繘鍒跺笺佸竷灏斿煎拰NULL銆傛湰鑺傝繕鍖呮嫭鍦MySQL涓鐞嗚繖浜涘熀鏈被鍨嬫椂浼氶亣鍒扮殑鍚勭缁嗗井宸埆鍜屸滃奖鍗扮増鈥濄
瀛楃涓叉寚鐢ㄥ崟寮曞彿(鈥'鈥)鎴栧弻寮曞彿(鈥"鈥)寮曡捣鏉ョ殑瀛楃搴忓垪銆備緥濡傦細
'a string'
"another string"
濡傛灉SQL鏈嶅姟鍣ㄦā寮忓惎鐢ㄤ簡NSI_QUOTES锛屽彲浠ュ彧鐢ㄥ崟寮曞彿寮曠敤瀛楃涓层傜敤鍙屽紩鍙峰紩鐢ㄧ殑瀛楃涓茶瑙i噴涓轰竴涓瘑鍒銆
瀛楃涓插彲浠ユ湁涓涓彲閫夊瓧绗﹂泦寮曚粙璇嶅拰COLLATE瀛愬彞锛
[_charset_name]'string' [COLLATE collation_name]
渚嬪锛
SELECT _latin1'string';
SELECT _latin1'string' COLLATE latin1_danish_ci;
鍏充簬杩欎簺瀛楃涓茶娉曞舰寮忕殑璇︾粏淇℃伅锛屽弬瑙10.3.7鑺傦紝鈥滃瓧绗︿覆鏂囧瓧瀛楃闆嗗拰鏍″鈥銆
鍦ㄥ瓧绗︿覆涓紝鏌愪簺搴忓垪鍏锋湁鐗规畩鍚箟銆傝繖浜涘簭鍒楀潎鐢ㄥ弽鏂滅嚎(鈥\鈥)寮濮嬶紝鍗虫墍璋撶殑杞箟瀛楃銆MySQL璇嗗埆涓嬮潰鐨勮浆涔夊簭鍒楋細
\0 |
ASCII 0(NUL)瀛楃銆 |
\' |
鍗曞紩鍙(鈥'鈥)銆 |
\" |
鍙屽紩鍙(鈥"鈥)銆 |
\b |
閫鏍肩銆 |
\n |
鎹㈣绗︺ |
\r |
鍥炶溅绗︺ |
\t |
tab瀛楃銆 |
\Z |
ASCII 26(鎺у埗锛Ctrl锛-Z)銆傝瀛楃鍙互缂栫爜涓衡\Z鈥欙紝浠ュ厑璁镐綘瑙e喅鍦Windows涓ASCII 26浠h〃鏂囦欢缁撳熬杩欎竴闂銆(濡傛灉浣犺瘯鍥句娇鐢mysql db_name < file_name锛ASCII 26浼氬甫鏉ラ棶棰橈級銆 |
\\ |
鍙嶆枩绾(鈥\鈥)瀛楃銆 |
\% |
鈥%鈥欏瓧绗︺傚弬瑙佽〃鍚庨潰鐨勬敞瑙c |
\_ |
鈥_鈥欏瓧绗︺傚弬瑙佽〃鍚庨潰鐨勬敞瑙c |
杩欎簺搴忓垪瀵瑰ぇ灏忓啓鏁忔劅銆備緥濡傦紝鈥\b鈥欒В閲婁负閫鏍硷紝浣嗏\B鈥欒В閲婁负鈥B鈥欍
鈥\%鈥欏拰鈥\_鈥欏簭鍒楃敤浜庢悳绱㈠彲鑳戒細瑙i噴涓洪氶厤绗︾殑妯″紡鍖归厤鐜涓殑鈥%鈥欏拰鈥_鈥欐枃瀛楀疄渚嬨傚弬瑙12.3.1鑺傦紝鈥滃瓧绗︿覆姣旇緝鍑芥暟鈥銆傝娉ㄦ剰濡傛灉浣犲湪鍏跺畠鐜涓娇鐢ㄢ\%鈥欐垨鈥\_鈥欙紝瀹冧滑杩斿洖瀛楃涓测\%鈥欏拰鈥\_鈥欙紝鑰屼笉鏄%鈥欏拰鈥_鈥欍
鍦ㄥ叾瀹冭浆涔夊簭鍒椾腑锛屽弽鏂滅嚎琚拷鐣ャ備篃灏辨槸璇达紝杞箟瀛楃瑙i噴涓轰豢浣涙病鏈夎浆涔夈
鏈夊嚑绉嶆柟寮忓彲浠ュ湪瀛楃涓蹭腑鍖呮嫭寮曞彿锛
路 鍦ㄥ瓧绗︿覆鍐呯敤鈥'鈥欏紩鐢ㄧ殑鈥'鈥欏彲浠ュ啓鎴愨''鈥欍
路 鍦ㄥ瓧绗︿覆鍐呯敤鈥"鈥欏紩鐢ㄧ殑鈥"鈥欏彲浠ュ啓鎴愨""鈥欍
路 鍙互鍦ㄥ紩鍙峰墠鍔犺浆涔夊瓧绗(鈥\鈥)銆
路 鍦ㄥ瓧绗︿覆鍐呯敤鈥"鈥欏紩鐢ㄧ殑鈥'鈥欎笉闇瑕佺壒娈婂鐞嗭紝涓嶉渶瑕佺敤鍙屽瓧绗︽垨杞箟銆傚悓鏍凤紝鍦ㄥ瓧绗︿覆鍐呯敤鈥'鈥欏紩鐢ㄧ殑鈥"鈥欎篃涓嶉渶瑕佺壒娈婂鐞嗐
涓嬮潰鐨SELECT璇彞鏄剧ず浜嗗紩鐢ㄥ拰杞箟濡備綍宸ヤ綔锛
mysql> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello';
+-------+---------+-----------+--------+--------+
| hello | "hello" | ""hello"" | hel'lo | 'hello |
+-------+---------+-----------+--------+--------+
mysql> SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello";
+-------+---------+-----------+--------+--------+
| hello | 'hello' | ''hello'' | hel"lo | "hello |
+-------+---------+-----------+--------+--------+
mysql> SELECT 'This\nIs\nFour\nLines';
+--------------------+
| This
Is
Four
Lines |
+--------------------+
mysql> SELECT 'disappearing\ backslash';
+------------------------+
| disappearing backslash |
+------------------------+
濡傛灉浣犳兂瑕佸湪瀛楃涓插垪鍐呮彃鍏ヤ簩杩涘埗鏁版嵁(渚嬪BLOB)锛屽繀椤婚氳繃杞箟搴忓垪琛ㄧず涓嬮潰鐨勫瓧绗︼細
NUL |
NUL瀛楄妭(ASCII 0)銆傜敤鈥\0鈥琛ㄧず璇ュ瓧绗(鍙嶆枩绾垮悗闈㈣窡涓涓ASCII鈥0鈥欏瓧绗)銆 |
\ |
鍙嶆枩绾(ASCII 92)銆傜敤鈥\\鈥欒〃绀鸿瀛楃銆 |
' |
鍗曞紩鍙(ASCII 39)銆傜敤鈥\'鈥欒〃绀鸿瀛楃銆 |
" |
鍙屽紩鍙(ASCII 34)銆傜敤鈥\"鈥欒〃绀鸿瀛楃銆 |
褰撶紪鍐欏簲鐢ㄧ▼搴忔椂锛屽湪鍖呭惈杩欎簺鐗规畩瀛楃鐨勫瓧绗︿覆鐢ㄤ簬鍙戦佸埌MySQL鏈嶅姟鍣ㄧ殑SQL璇彞涓殑鏁版嵁鍊间箣鍓嶏紝蹇呴』瀵瑰畠浠纭繘琛岃浆涔夈傚彲浠ョ敤涓ょ鏂规硶鏉ュ畬鎴愶細
路 鐢ㄨ浆涔夌壒娈婂瓧绗︾殑鍑芥暟澶勭悊瀛楃涓层備緥濡傦紝鍦C绋嬪簭涓紝鍙互浣跨敤mysql_real_escape_string() C API鍑芥暟鏉ヨ浆涔夊瓧绗︺傚弬瑙25.2.3.52鑺傦紝鈥渕ysql_real_escape_string()鈥銆Perl DBI鎺ュ彛鎻愪緵涓涓quote鏂规硶鏉ュ皢鐗规畩瀛楃杞崲涓烘纭殑杞箟搴忓垪銆傚弬瑙25.4鑺傦紝鈥淢ySQL Perl API鈥銆
路 鏄惧紡杞箟鐗规畩瀛楃锛岃澶MySQL API鎻愪緵浜嗗崰浣嶇鍔熻兘锛屽厑璁镐綘鍦ㄦ煡璇㈠瓧绗︿覆涓彃鍏ョ壒娈婃爣璁帮紝鐒跺悗褰撲綘鍙戝嚭鏌ヨ鏃跺皢鏁版嵁鍊煎悓瀹冧滑缁戝畾璧锋潵銆傚湪杩欑鎯呭喌涓嬶紝API鍏虫敞杞箟鍊间腑鐨勭壒娈婂瓧绗︺
鏁存暟鐢ㄤ竴绯诲垪闃挎媺浼暟瀛楄〃绀恒傛诞鐐规暟浣跨敤鈥.鈥欎綔涓哄崄杩涘埗闂撮殧绗︺備袱绉嶇被鍨嬬殑鏁板煎潎鍙互鍦ㄥ墠闈㈠姞涓涓-鈥欐潵琛ㄧず璐熷笺
鍚堟硶鏁存暟鐨勪緥瀛愶細
1221
0
-32
鍚堟硶娴偣鏁扮殑渚嬪瓙锛
294.42
-32032.6809e+10
148.00
鏁存暟鍙互鐢ㄥ湪娴偣鐜涓紱瀹冭瑙i噴涓轰笌娴偣鏁扮瓑鏁堛
MySQL鏀寔鍗佸叚杩涘埗鍊笺傚湪鏁板瓧涓婁笅鏂囦腑锛屽崄鍏繘鍒舵暟濡傚悓鏁存暟(64浣嶇簿搴)銆傚湪瀛楃涓蹭笂涓嬫枃锛屽鍚屼簩杩涘埗瀛楃涓诧紝姣忓鍗佸叚杩涘埗鏁板瓧琚浆鎹负涓涓瓧绗︼細
mysql> SELECT x'4D7953514C'锛
-> 'MySQL'
mysql> SELECT 0xa+0锛
-> 10
mysql> SELECT 0x5061756c锛
-> 'Paul'
鍗佸叚杩涘埗鍊肩殑榛樿绫诲瀷鏄瓧绗︿覆銆傚鏋滄兂瑕佺‘淇濊鍊间綔涓烘暟瀛楀鐞嗭紝鍙互浣跨敤CAST(...AS UNSIGNED)锛
mysql> SELECT 0x41锛CAST(0x41 AS UNSIGNED)锛
-> 'A'锛65
0x璇硶鍩轰簬ODBC銆傚崄鍏繘鍒跺瓧绗︿覆閫氬父鐢ㄤ簬ODBC浠ヤ究涓BLOB鍒楁彁渚涘笺x鈥hexstring鈥璇硶鍩轰簬鏍囧噯SQL銆
鍙互鐢HEX()鍑芥暟灏嗕竴涓瓧绗︿覆鎴栨暟瀛楄浆鎹负鍗佸叚杩涘埗鏍煎紡鐨勫瓧绗︿覆锛
mysql> SELECT HEX('cat')锛
-> '636174'
mysql> SELECT 0x636174锛
-> 'cat'
鍙互浣跨敤b'value'绗﹀彿鍐欎綅瀛楁鍊笺value鏄竴涓敤0鍜1鍐欐垚鐨勪簩杩涘埗鍊笺
浣嶅瓧娈电鍙峰彲浠ユ柟渚挎寚瀹氬垎閰嶇粰BIT鍒楃殑鍊硷細
mysql> CREATE TABLE t (b BIT(8));
mysql> INSERT INTO t SET b = b'11111111';
mysql> INSERT INTO t SET b = b'1010';
+------+----------+----------+----------+
| b+0 | BIN(b+0) | OCT(b+0) | HEX(b+0) |
+------+----------+----------+----------+
| 255 | 11111111 | 377 | FF |
| 10 | 1010 | 12 | A |
+------+----------+----------+----------+
NULL鍊艰〃绀衡滄病鏈鏁版嵁鈥濄NULL鍙互鍐欐垚澶у啓鎴栧皬鍐欍
璇锋敞鎰NULL鍊间笉鍚屼簬鏁板瓧绫诲瀷鐨0鎴栧瓧绗︿覆绫诲瀷鐨勭┖瀛楃涓层傚弬瑙A.5.3鑺傦紝鈥滀笌NULL鍊兼湁鍏崇殑闂鈥銆
瀵逛簬鐢LOAD DATA INFILE鎴SELECT ...INTO OUTFILE鎵ц鐨勬枃鏈枃浠跺鍏ユ垨瀵煎嚭鎿嶄綔锛NULL鐢ㄥ簭鍒\N琛ㄧず銆傚弬瑙13.2.5鑺傦紝鈥淟OAD DATA INFILE璇硶鈥銆
鏁版嵁搴撱佽〃銆佺储寮曘佸垪鍜屽埆鍚嶆槸璇嗗埆绗︺傝鑺傛弿杩颁簡鍦MySQL涓瘑鍒鐨勫厑璁哥殑璇硶銆
涓嬮潰鐨勮〃鎻忚堪浜嗘瘡绫昏瘑鍒鐨勬渶澶ч暱搴﹀拰鍏佽鐨勫瓧绗︺
璇嗗埆绗 |
鏈澶ч暱搴(瀛楄妭) |
鍏佽鐨勫瓧绗 |
鏁版嵁搴 |
64 |
鐩綍鍚嶅厑璁哥殑浠讳綍瀛楃锛屼笉鍖呮嫭鈥/鈥欍佲\鈥欐垨鑰呪銆鈥 |
琛 |
64 |
鏂囦欢鍚嶅厑璁哥殑浠讳綍瀛楃锛屼笉鍖呮嫭鈥/鈥欍佲\鈥欐垨鑰呪銆鈥 |
鍒 |
64 |
鎵鏈夊瓧绗 |
绱㈠紩 |
64 |
鎵鏈夊瓧绗 |
鍒悕 |
255 |
鎵鏈夊瓧绗 |
闄や簡琛ㄥ唴娉ㄦ槑鐨勯檺鍒讹紝璇嗗埆绗︿笉鍙互鍖呭惈ASCII 0鎴栧间负255鐨勫瓧鑺傘傛暟鎹簱銆佽〃鍜屽垪鍚嶄笉搴斾互绌烘牸缁撳熬銆傚湪璇嗗埆绗︿腑鍙互浣跨敤寮曞彿璇嗗埆绗︼紝灏界搴斿敖鍙兘閬垮厤杩欐牱浣跨敤銆
璇嗗埆绗︾敤Unicode(UTF8)淇濆瓨銆傚湪.frm鏂囦欢涓繚瀛樼殑琛ㄥ畾涔夌殑璇嗗埆绗﹀拰鍦mysql鏁版嵁搴撲腑鐨勬巿鏉冭〃淇濆瓨鐨勮瘑鍒涔熺敤Unicode(UTF8)淇濆瓨銆傚湪MySQL 5.1涓巿鏉冭〃(鍜屽叾瀹冭〃)鐨勫瓧绗︿覆鍒楃殑澶у皬绛変簬瀛楃涓暟锛涜繖璇存槑(涓嶈薄浠ュ墠鐗堟湰鐨MySQL)浣犲彲浠ュ湪杩欎簺鍒椾繚瀛樼殑鍊间腑浣跨敤澶氬瓧鑺傚瓧绗﹁屼笉闇瑕侀檷浣庡瓧绗︿釜鏁般
璇嗗埆绗﹀彲浠ュ紩璧锋潵涔熷彲浠ヤ笉寮曡捣鏉ャ傚鏋滆瘑鍒鏄竴涓繚鐣欏瓧鎴栧寘鍚壒娈婂瓧绗︼紝鏃犺浣曟椂浣跨敤锛蹇呴』灏嗗畠寮曡捣鏉ャ傚叧浜庝繚鐣欏瓧鐨勫垪琛ㄥ弬瑙9.6鑺傦紝鈥淢ySQL涓繚鐣欏瓧鐨勫鐞嗏銆傜壒娈婂瓧绗︽寚閭d簺褰撳墠瀛楃闆嗐佲_鈥欏拰鈥$鈥欎箣澶栫殑鏂囧瓧鏁板瓧瀛楃闆嗐
璇嗗埆绗︾殑寮曠敤绗︽槸鍙嶅嬀鍙(鈥`鈥)锛
mysql> SELECT * FROM `select` WHERE `select`.id > 100;
濡傛灉SQL鏈嶅姟鍣ㄦā寮忓寘鎷ANSI_QUOTES妯″紡閫夐」锛岃繕鍙互鐢ㄥ弻寮曞彿灏嗚瘑鍒寮曡捣鏉ワ細
mysql> CREATE TABLE "test" (col INT);
ERROR 1064: You have an error in your SQL syntax. (...)
mysql> SET sql_mode='ANSI_QUOTES';
mysql> CREATE TABLE "test" (col INT);
Query OK, 0 rows affected (0.00 sec)
濡傛灉浣犲紩鐢ㄨ瘑鍒锛屽彲浠ュ湪璇嗗埆绗﹀唴鍖呮嫭璇嗗埆绗﹀紩鐢ㄧ銆傚鏋滆瘑鍒鍐呭寘鎷殑瀛楃涓庡紩鐢ㄨ瘑鍒鐨勫瓧绗︾浉鍚岋紝鍒欓渶瑕佺敤鍙屽瓧绗︺備笅闈㈢殑璇彞鍒涘缓涓涓悕涓a`b鍖呭惈鍒c"d鐨勮〃锛
mysql> CREATE TABLE `a``b` (`c"d` INT)锛
寤鸿涓嶈浣跨敤XeX妯″紡鐨勫悕锛屼緥濡1e鎴2e2锛屽洜涓虹被浼1e+1鐨勮〃杈惧紡姣旇緝妯$硦銆傛牴鎹笂涓嬫枃锛屽畠鍙互瑙i噴涓鸿〃杈惧紡1e + 1鎴栨暟瀛1e+1銆
浣跨敤MD5浜х敓琛ㄥ悕鏃跺簲浠旂粏锛屽洜涓哄畠鍙兘浜х敓涓嶅悎娉曠殑琛ㄥ悕锛屽涓婃墍杩般
MySQL鍏佽浣跨敤鐢卞崟涓瘑鍒鎴栧涓瘑鍒缁勬垚鐨勫悕瀛椼傚閮ㄥ垎鍚嶅悇缁勪欢涔嬮棿搴斾互鍙ョ偣(鈥.鈥)闂撮殧寮銆傚閮ㄥ垎鍚嶇殑寮澶撮儴鍒嗕綔涓洪檺瀹氳瘝锛屽悗闈㈢殑璇嗗埆绗﹁瑙i噴銆
鍦MySQL涓彲浠ュ紩鐢ㄤ笅闈㈠舰寮忕殑鍒楋細
鍒楀弬鑰 |
鍚箟 |
col_name |
鍒col_name锛屾煡璇腑浣跨敤鐨勮〃鍖呭惈鏈夋鍚嶅瓧鐨勫垪銆 |
tbl_name.col_name |
榛樿鏁版嵁搴撲腑鐨勮〃tbl_name鐨勫垪col_name銆 |
db_name.tbl_name.col_name |
鏁版嵁搴db_name涓殑琛tbl_name鐨勫垪col_name銆 |
濡傛灉澶氶儴鍒嗗悕鐨勭粍浠堕渶瑕佸紩鐢紝搴斿垎鍒皢瀹冧滑寮曡捣鏉ヨ屼笉瑕佸皢鏁翠釜鍚嶅紩璧锋潵銆備緥濡傦紝`my-tables`.`my-column` 鏈夋晥锛岃`my-tables.my-column`鏃犳晥銆
涓嶉渶瑕佸湪璇彞涓负鍒楁寚瀹tbl_name鎴db_name.tbl_name鍓嶇紑锛岄櫎闈炲垪浼氬緢妯$硦銆傚亣瀹氳〃t1鍜t2鍚勫寘鍚竴涓垪c锛屼綘浣跨敤SELECT璇彞鍦t1鍜t2涓悳绱c銆傚湪杩欑鎯呭喌涓嬶紝c寰堟ā绯婏紝鍥犱负瀹冨湪璇彞涓娇鐢ㄧ殑琛ㄥ唴涓嶅敮涓銆備綘蹇呴』鐢ㄨ〃鍚t1.c鎴t2.c闄愬畾瀹冿紝琛ㄧず鎸囧摢涓〃銆傚悓鏍凤紝瑕佹兂鐢ㄥ悓涓璇彞鎼滅储鏁版嵁搴db1涓殑琛t鍜屾暟鎹簱db2涓殑琛t锛屼綘蹇呴』灏嗛偅浜涜〃涓殑鍒楁寚涓db1.t.col_name鍜db2.t.col_name銆
闄愬畾鍚嶄腑鍙ョ偣鍚庨潰鐨勫瓧蹇呴』涓轰竴涓瘑鍒锛屽洜姝や笉闇瑕佸皢瀹冨紩璧锋潵锛屽嵆浣挎槸涓涓繚鐣欏瓧銆
璇硶.tbl_name琛ㄧず褰撳墠鏁版嵁搴撲腑鐨tbl_name銆傝璇硶涓ODBC鍏煎锛屽洜涓烘煇浜ODBC绋嬪簭鍦ㄨ〃鍚嶅墠闈㈠姞鍓嶇紑鈥.鈥欏瓧绗︺
鍦MySQL涓紝鏁版嵁搴撳搴旀暟鎹洰褰曚腑鐨勭洰褰曘傛暟鎹簱涓殑姣忎釜琛ㄨ嚦灏戝搴旀暟鎹簱鐩綍涓殑涓涓枃浠(涔熷彲鑳芥槸澶氫釜锛屽彇鍐充簬瀛樺偍寮曟搸)銆傚洜姝わ紝鎵浣跨敤鎿嶄綔绯荤粺鐨勫ぇ灏忓啓鏁忔劅鎬у喅瀹氫簡鏁版嵁搴撳悕鍜岃〃鍚嶇殑澶у皬鍐欐晱鎰熸с傝繖璇存槑鍦ㄥぇ澶氭暟Unix涓暟鎹簱鍚嶅拰琛ㄥ悕瀵瑰ぇ灏忓啓鏁忔劅锛岃屽湪Windows涓澶у皬鍐欎笉鏁忔劅銆備竴涓樉钁楃殑渚嬪鎯呭喌鏄Mac OS X锛屽畠鍩轰簬Unix浣嗕娇鐢ㄩ粯璁ゆ枃浠剁郴缁熺被鍨(HFS+)锛屽澶у皬鍐欎笉鏁忔劅銆傜劧鑰岋紝Mac OS X涔熸敮鎸UFS鍗凤紝璇ュ嵎瀵瑰ぇ灏忓啓鏁忔劅锛屽氨鍍Unix涓鏍枫傚弬瑙1.8.4鑺傦紝鈥淢ySQL瀵规爣鍑哠QL鐨勬墿灞曗銆
娉ㄩ噴锛灏界鍦ㄦ煇浜涘钩鍙颁腑鏁版嵁搴撳悕鍜岃〃鍚嶅澶у皬鍐欎笉鏁忔劅锛屼笉搴斿湪鍚屼竴鏌ヨ涓娇鐢ㄤ笉鍚岀殑澶у皬鍐欐潵寮曠敤缁欏畾鐨勬暟鎹簱鎴栬〃銆備笅闈㈢殑鏌ヨ涓嶄細宸ヤ綔锛屽洜涓哄畠鍚屾椂寮曠敤浜嗚〃my_tables鍜as MY_tables锛
mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;
鍒椼佺储寮曘佸瓨鍌ㄥ瓙绋嬪簭鍜岃Е鍙戝櫒鍚嶅湪浠讳綍骞冲彴涓婂澶у皬鍐欎笉鏁忔劅锛屽垪鐨勫埆鍚嶄篃涓嶆晱鎰熴
榛樿鎯呭喌锛岃〃鍒悕鍦Unix涓澶у皬鍐欐晱鎰燂紝浣嗗湪Windows鎴Mac OS X涓澶у皬鍐欎笉鏁忔劅銆備笅闈㈢殑鏌ヨ鍦Unix涓笉浼氬伐浣滐紝鍥犱负瀹冨悓鏃跺紩鐢ㄤ簡鍒悕a鍜A锛
mysql> SELECT col_name FROM tbl_name AS a
-> WHERE a.col_name = 1 OR A.col_name = 2;
鐒惰岋紝璇ユ煡璇㈠湪Windows涓槸鍙互鐨勩傝鎯抽伩鍏嶅嚭鐜板樊鍒紝鏈濂介噰鐢ㄤ竴鑷寸殑杞崲锛屼緥濡傛绘槸鐢ㄥ皬鍐欏垱寤哄苟寮曠敤鏁版嵁搴撳悕鍜岃〃鍚嶃傚湪澶у鏁扮Щ妞嶅拰浣跨敤涓缓璁娇鐢ㄨ杞崲銆
鍦MySQL涓浣曞湪纭洏涓婁繚瀛樺拰浣跨敤琛ㄥ悕鍜屾暟鎹簱鍚嶇敱lower_case_tables_name绯荤粺鍙橀噺纭畾锛屽彲浠ュ湪鍚姩mysqld鏃惰缃lower_case_tables_name鍙互閲囩敤涓嬮潰鐨勪换涓鍊硷細
鍊 |
鍚箟 |
0 |
浣跨敤CREATE TABLE鎴CREATE DATABASE璇彞鎸囧畾鐨勫ぇ鍐欏拰灏忓啓鍦ㄧ‖鐩樹笂淇濆瓨琛ㄥ悕鍜屾暟鎹簱鍚嶃傚悕绉版瘮杈冨澶у皬鍐欐晱鎰熴傚湪Unix绯荤粺涓殑榛樿璁剧疆鍗冲姝ゃ傝娉ㄦ剰濡傛灉鍦ㄥぇ灏忓啓涓嶆晱鎰熺殑鏂囦欢绯荤粺涓婄敤--lower-case-table-names=0寮哄埗璁句负0锛屽苟涓斾娇鐢ㄤ笉鍚岀殑澶у皬鍐欒闂MyISAM琛ㄥ悕锛屼細瀵艰嚧绱㈠紩鐮村潖銆 |
1 |
琛ㄥ悕鍦ㄧ‖鐩樹笂浠ュ皬鍐欎繚瀛橈紝鍚嶇О姣旇緝瀵瑰ぇ灏忓啓鏁忔劅銆MySQL灏嗘墍鏈夎〃鍚嶈浆鎹负灏忓啓浠ヤ究瀛樺偍鍜屾煡鎵俱傝琛屼负涔熼傚悎鏁版嵁搴撳悕鍜岃〃鐨勫埆鍚嶃傝鍊间负Windows鍜Mac OS X绯荤粺涓殑榛樿鍊笺 |
2 |
琛ㄥ悕鍜屾暟鎹簱鍚嶅湪纭洏涓婁娇鐢CREATE TABLE鎴CREATE DATABASE璇彞鎸囧畾鐨勫ぇ灏忓啓杩涜淇濆瓨锛屼絾MySQL灏嗗畠浠浆鎹负灏忓啓浠ヤ究鏌ユ壘銆傚悕绉版瘮杈冨澶у皬鍐欐晱鎰熴娉閲婏細鍙鍦ㄥ澶у皬鍐欎笉鏁忔劅鐨勬枃浠剁郴缁熶笂閫傜敤! InnoDB琛ㄥ悕浠ュ皬鍐欎繚瀛橈紝渚嬪lower_case_tables_name=1銆 |
鍦Windows鍜Mac OS X涓紝lower_case_tables_name鐨 榛樿鍊兼槸1銆
濡傛灉鍙湪涓涓钩鍙颁笂浣跨敤MySQL锛岄氬父涓嶉渶瑕佹洿鏀lower_case_tables_name鍙橀噺銆傜劧鑰岋紝濡傛灉浣犳兂瑕佸湪瀵瑰ぇ灏忓啓鏁忔劅涓嶅悓鐨勬枃浠剁郴缁熺殑骞冲彴涔嬮棿杞Щ琛紝浼氶亣鍒板洶闅俱備緥濡傦紝鍦Unix涓紝my_tables鍜MY_tables鏄袱涓笉鍚岀殑琛紝浣嗗湪Windows涓紝杩欎袱涓〃鍚嶇浉鍚屻傝鎯抽伩鍏嶇敱浜庢暟鎹簱鎴栬〃鍚嶇殑澶у皬鍐欓犳垚鐨勬暟鎹浆绉婚棶棰橈紝鍙娇鐢ㄤ袱涓夐」锛
路 鍦ㄤ换浣曠郴缁熶腑鍙互浣跨敤lower_case_tables_name=1銆備娇鐢ㄨ閫夐」鐨勪笉鍒╀箣澶勬槸褰撲娇鐢SHOW TABLES鎴SHOW DATABASES鏃讹紝鐪嬩笉鍑哄悕瀛楀師鏉ユ槸鐢ㄥぇ鍐欒繕鏄皬鍐欍
路 鍦Unix涓娇鐢lower_case_tables_name=0锛屽湪Windows涓娇鐢lower_case_tables_name=2銆傝繖鏍蜂簡鍙互淇濈暀鏁版嵁搴撳悕鍜岃〃鍚嶇殑澶у皬鍐欍備笉鍒╀箣澶勬槸蹇呴』纭繚鍦Windows涓煡璇㈡绘槸鐢ㄦ纭ぇ灏忓啓寮曠敤鏁版嵁搴撳悕鍜岃〃鍚嶃傚鏋滃皢鏌ヨ杞Щ鍒Unix涓紝鐢变簬鍦Unix涓ぇ灏忓啓寰堥噸瑕侊紝濡傛灉澶у皬鍐欎笉姝g‘锛屽畠浠笉宸ヤ綔銆
渚嬪锛氬鏋滀綘姝d娇鐢InnoDB琛紝鍦ㄤ换浣曞钩鍙颁笂鍧囧簲灏lower_case_tables_name璁剧疆涓1锛屼互寮哄埗灏嗗悕杞崲涓哄皬鍐欍
璇锋敞鎰忓湪Unix涓皢lower_case_tables_name璁剧疆涓1涔嬪墠锛岄噸鍚mysqld涔嬪墠锛屽繀椤诲厛灏嗘棫鐨勬暟鎹簱鍚嶅拰琛ㄥ悕杞崲涓哄皬鍐欍
鍙互鍏堝湪鐢ㄦ埛鍙橀噺涓繚瀛樺肩劧鍚庡湪浠ュ悗寮曠敤瀹冿紱杩欐牱鍙互灏嗗间粠涓涓鍙ヤ紶閫掑埌鍙︿竴涓鍙ャ鐢ㄦ埛鍙橀噺涓庤繛鎺ユ湁鍏銆備篃灏辨槸璇达紝涓涓鎴风瀹氫箟鐨勫彉閲忎笉鑳借鍏跺畠瀹㈡埛绔湅鍒版垨浣跨敤銆傚綋瀹㈡埛绔鍑烘椂锛岃瀹㈡埛绔繛鎺ョ殑鎵鏈夊彉閲忓皢鑷姩閲婃斁銆
鐢ㄦ埛鍙橀噺鐨勫舰寮忎负@var_name锛屽叾涓彉閲忓悕var_name鍙互鐢卞綋鍓嶅瓧绗﹂泦鐨勬枃瀛楁暟瀛楀瓧绗︺佲.鈥欍佲_鈥欏拰鈥$鈥欑粍鎴愩 榛樿瀛楃闆嗘槸cp1252 (Latin1)銆傚彲浠ョ敤mysqld鐨--default-character-set閫夐」鏇存敼瀛楃闆嗐傚弬瑙5.10.1鑺傦紝鈥滄暟鎹拰鎺掑簭鐢ㄥ瓧绗﹂泦鈥銆傜敤鎴峰彉閲忓悕瀵瑰ぇ灏忓啓涓嶆晱鎰熴
璁剧疆鐢ㄦ埛鍙橀噺鐨勪竴涓斿緞鏄墽琛SET璇彞锛
SET @var_name = expr [, @var_name = expr] ...
瀵逛簬SET锛屽彲浠ヤ娇鐢=鎴:=浣滀负鍒嗛厤绗︺傚垎閰嶇粰姣忎釜鍙橀噺鐨expr鍙互涓烘暣鏁般佸疄鏁般佸瓧绗︿覆鎴栬NULL鍊笺
涔熷彲浠ョ敤璇彞浠f浛SET鏉ヤ负鐢ㄦ埛鍙橀噺鍒嗛厤涓涓笺傚湪杩欑鎯呭喌涓嬶紝鍒嗛厤绗﹀繀椤讳负:=鑰屼笉鑳界敤=锛屽洜涓哄湪闈SET璇彞涓=琚涓轰竴涓瘮杈 鎿嶄綔绗︼細
mysql> SET @t1=0, @t2=0, @t3=0;
mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
+----------------------+------+------+------+
| @t1:=(@t2:=1)+@t3:=4 | @t1 | @t2 | @t3 |
+----------------------+------+------+------+
| 5 | 5 | 1 | 4 |
+----------------------+------+------+------+
鐢ㄦ埛鍙橀噺鍙互鐢ㄤ簬琛ㄨ揪寮忎腑銆傜洰鍓嶄笉鍖呮嫭鏄庢樉闇瑕佹枃瀛楀肩殑涓婁笅鏂囦腑锛屼緥濡SELECT璇彞鐨LIMIT瀛愬彞锛屾垨鑰LOAD DATA璇彞鐨IGNORE number LINES瀛愬彞銆
濡傛灉浣跨敤娌℃湁鍒濆鍖栫殑鍙橀噺锛屽叾鍊兼槸NULL銆
濡傛灉鐢ㄦ埛鍙橀噺鍒嗛厤浜嗕竴涓瓧绗︿覆鍊硷紝鍏跺瓧绗﹂泦鍜屾牎瀵硅鍒欎笌璇ュ瓧绗︿覆鐨勭浉鍚屻傜敤鎴峰彉閲忕殑鍙帇缂╂э紙coercibility锛夋槸闅愬惈鐨勩(鍗充负琛ㄥ垪鍊肩殑鐩稿悓鐨勫彲鍘嬬缉鎬э紙coercibility锛夈
娉ㄩ噴锛鍦SELECT璇彞涓紝琛ㄨ揪寮忓彂閫佸埌瀹㈡埛绔悗鎵嶈繘琛岃绠椼傝繖璇存槑鍦HAVING銆GROUP BY鎴栬ORDER BY瀛愬彞涓紝涓嶈兘浣跨敤鍖呭惈SELECT鍒楄〃涓墍璁剧殑鍙橀噺鐨勮〃杈惧紡銆備緥濡傦紝涓嬮潰鐨勮鍙ヤ笉鑳芥寜鏈熸湜宸ヤ綔锛
mysql> SELECT (@aa:=id) AS a锛(@aa+3) AS b 浠tbl_name HAVING b=5锛
HAVING瀛愬彞涓紩鐢ㄤ簡SELECT鍒楄〃涓殑琛ㄨ揪寮忕殑鍒悕锛屼娇鐢@aa銆備笉鑳芥寜鏈熸湜宸ヤ綔锛@aa涓嶅寘鍚綋鍓嶈鐨勫硷紝鑰屾槸鍓嶉潰鎵閫夌殑琛岀殑id鍊笺
涓鑸師鍒欐槸涓嶈鍦ㄨ鍙ョ殑涓涓儴鍒嗕负鐢ㄦ埛鍙橀噺鍒嗛厤涓涓艰屽湪鍚屼竴璇彞鐨勫叾瀹冮儴鍒嗕娇鐢ㄨ鍙橀噺銆傚彲鑳戒細寰楀埌鏈熸湜鐨勭粨鏋滐紝浣嗕笉鑳戒繚璇併
璁剧疆鍙橀噺骞跺湪鍚屼竴璇彞涓娇鐢ㄥ畠鐨勫彟涓涓棶棰樻槸鍙橀噺鐨勯粯璁ょ粨鏋滅殑绫诲瀷鍙栧喅浜庤鍙ュ墠闈㈢殑鍙橀噺绫诲瀷銆備笅闈㈢殑渚嬪瓙璇存槑浜嗚鐐癸細
mysql> SET @a='test';
mysql> SELECT @a,(@a:=20) FROM tbl_name;
瀵逛簬璇 SELECT璇彞锛MySQL鍚戝鎴风鎶ュ憡绗1鍒楁槸涓涓瓧绗︿覆锛屽苟涓斿皢@a鐨勬墍鏈夎闂浆鎹负瀛楃涓诧紝鍗充娇@a鍦ㄧ2琛屼腑璁剧疆涓轰竴涓暟瀛椼傛墽琛屽畬SELECT璇彞鍚庯紝@a琚涓轰笅涓璇彞鐨勪竴涓暟瀛椼
瑕佹兂閬垮厤杩欑闂锛岃涔堜笉鍦ㄥ悓涓涓鍙ヤ腑璁剧疆骞朵娇鐢ㄧ浉鍚岀殑鍙橀噺锛岃涔堝湪浣跨敤鍓嶅皢鍙橀噺璁剧疆涓0銆0.0鎴栬''浠ュ畾涔夊叾绫诲瀷銆
鏈垎閰嶇殑鍙橀噺鏈変竴涓NULL锛岀被鍨嬩负瀛楃涓层
MySQL鍙互璁块棶璁稿绯荤粺鍜岃繛鎺ュ彉閲忋傚綋鏈嶅姟鍣ㄨ繍琛屾椂璁稿鍙橀噺鍙互鍔ㄦ佹洿鏀广傝繖鏍烽氬父鍏佽浣犱慨鏀规湇鍔″櫒鎿嶄綔鑰屼笉闇瑕佸仠姝㈠苟閲嶅惎鏈嶅姟鍣ㄣ
mysqld鏈嶅姟鍣ㄧ淮鎶や袱绉嶅彉閲忋傚叏灞鍙橀噺褰卞搷鏈嶅姟鍣ㄦ暣浣撴搷浣溿備細璇濆彉閲忓奖鍝嶅叿浣撳鎴风杩炴帴鐨勬搷浣溿
褰撴湇鍔″櫒鍚姩鏃讹紝瀹冨皢鎵鏈夊叏灞鍙橀噺鍒濆鍖栦负榛樿鍊笺傝繖浜涢粯璁ゅ煎彲浠ュ湪閫夐」鏂囦欢涓垨鍦ㄥ懡浠よ涓寚瀹氱殑閫夐」杩涜鏇存敼銆傛湇鍔″櫒鍚姩鍚庯紝閫氳繃杩炴帴鏈嶅姟鍣ㄥ苟鎵цSET GLOBAL var_name璇彞锛屽彲浠ュ姩鎬佹洿鏀硅繖浜涘叏灞鍙橀噺銆傝鎯虫洿鏀瑰叏灞鍙橀噺锛屽繀椤诲叿鏈SUPER鏉冮檺銆
鏈嶅姟鍣ㄨ繕涓烘瘡涓繛鎺ョ殑瀹㈡埛绔淮鎶や竴绯诲垪浼氳瘽鍙橀噺銆傚湪杩炴帴鏃朵娇鐢ㄧ浉搴斿叏灞鍙橀噺鐨勫綋鍓嶅煎瀹㈡埛绔殑浼氳瘽鍙橀噺杩涜鍒濆鍖栥傚浜庡姩鎬佷細璇濆彉閲忥紝瀹㈡埛绔彲浠ラ氳繃SET SESSION var_name璇彞鏇存敼瀹冧滑銆傝缃細璇濆彉閲忎笉闇瑕佺壒娈婃潈闄愶紝浣嗗鎴风鍙兘鏇存敼鑷繁鐨勪細璇濆彉閲忥紝鑰屼笉鑳芥洿鏀瑰叾瀹冨鎴风鐨勪細璇濆彉閲忋
瀵逛簬鍏ㄥ眬鍙橀噺鐨勬洿鏀瑰彲浠ヨ璁块棶璇ュ叏灞鍙橀噺鐨勪换浣曞鎴风鐪嬭銆傜劧鑰岋紝瀹冨彧褰卞搷鏇存敼鍚庤繛鎺ョ殑瀹㈡埛鐨勪粠璇ュ叏灞鍙橀噺鍒濆鍖栫殑鐩稿簲浼氳瘽鍙橀噺銆備笉褰卞搷鐩墠宸茬粡杩炴帴鐨勫鎴风鐨勪細璇濆彉閲(鍗充娇瀹㈡埛绔墽琛SET GLOBAL璇彞涔熶笉褰卞搷)銆
鍙互浣跨敤鍑犵璇硶褰㈠紡鏉ヨ缃垨妫绱㈠叏灞鎴栦細璇濆彉閲忋備笅闈㈢殑渚嬪瓙浣跨敤浜sort_buffer_sizeas浣滀负绀轰緥鍙橀噺鍚嶃
瑕佹兂璁剧疆涓涓GLOBAL鍙橀噺鐨勫硷紝浣跨敤涓嬮潰鐨勮娉曪細
mysql> SET GLOBAL sort_buffer_size=value;
mysql> SET @@global.sort_buffer_size=value;
瑕佹兂璁剧疆涓涓SESSION鍙橀噺鐨勫硷紝浣跨敤涓嬮潰鐨勮娉曪細
mysql> SET SESSION sort_buffer_size=value;
mysql> SET @@session.sort_buffer_size=value;
mysql> SET sort_buffer_size=value;
LOCAL鏄SESSION鐨勫悓涔夎瘝銆
濡傛灉璁剧疆鍙橀噺鏃朵笉鎸囧畾GLOBAL銆SESSION鎴栬LOCAL锛岄粯璁や娇鐢SESSION銆傚弬瑙13.5.3鑺傦紝鈥淪ET璇硶鈥銆
瑕佹兂妫绱竴涓GLOBAL鍙橀噺鐨勫硷紝浣跨敤涓嬮潰鐨勮娉曪細
mysql> SELECT @@global.sort_buffer_size;
mysql> SHOW GLOBAL VARIABLES like 'sort_buffer_size';
瑕佹兂妫绱竴涓SESSION鍙橀噺鐨勫硷紝浣跨敤涓嬮潰鐨勮娉曪細
mysql> SELECT @@sort_buffer_size;
mysql> SELECT @@session.sort_buffer_size;
mysql> SHOW SESSION VARIABLES like 'sort_buffer_size';
杩欓噷锛LOCAL涔熸槸SESSION鐨勫悓涔夎瘝銆
褰撲綘鐢SELECT @@var_name鎼滅储涓涓彉閲忔椂(涔熷氨鏄锛屼笉鎸囧畾global.銆session.鎴栬local.)锛MySQL杩斿洖SESSION鍊硷紙濡傛灉瀛樺湪锛夛紝鍚﹀垯杩斿洖GLOBAL鍊笺
瀵逛簬SHOW VARIABLES锛屽鏋滀笉鎸囧畾GLOBAL銆SESSION鎴栬LOCAL锛MySQL杩斿洖SESSION鍊笺
褰撹缃GLOBAL鍙橀噺闇瑕GLOBAL鍏抽敭瀛椾絾妫绱㈡椂涓嶉渶瑕佸畠浠殑鍘熷洜鏄槻姝㈠皢鏉ュ嚭鐜伴棶棰樸傚鏋滄垜浠Щ闄や竴涓笌鏌愪釜GLOBAL鍙橀噺鍏锋湁鐩稿悓鍚嶅瓧鐨SESSION鍙橀噺锛屽叿鏈SUPER鏉冮檺鐨勫鎴峰彲鑳戒細鎰忓鍦版洿鏀GLOBAL鍙橀噺鑰屼笉鏄畠鑷繁鐨勮繛鎺ョ殑SESSION鍙橀噺銆傚鏋滄垜浠坊鍔犱竴涓笌鏌愪釜GLOBAL鍙橀噺鍏锋湁鐩稿悓鍚嶅瓧鐨SESSION鍙橀噺锛屾兂鏇存敼GLOBAL鍙橀噺鐨勫鎴峰彲鑳戒細鍙戠幇鍙湁鑷繁鐨SESSION鍙橀噺琚洿鏀逛簡銆
鍏充簬绯荤粺鍚姩閫夐」鍜岀郴缁熷彉閲忕殑璇︾粏淇℃伅鍙傝5.3.1鑺傦紝鈥mysqld鍛戒护琛岄夐」鈥鍜5.3.3鑺傦紝鈥滄湇鍔″櫒绯荤粺鍙橀噺鈥銆傚湪5.3.3.1鑺傦紝鈥滃姩鎬佺郴缁熷彉閲忊涓垪鍑轰簡鍙互鍦ㄨ繍琛屾椂璁剧疆鐨勫彉閲忋
缁撴瀯寮忓彉閲忓湪涓や釜鏂归潰涓嶅悓浜庡父瑙勭郴缁熷彉閲忥細
路 鍏跺兼槸涓涓惈缁勪欢鐨勭粨鏋勶紝鍙互鎸囧畾鏈嶅姟鍣ㄥ弬鏁帮紝涓鑸揣瀵嗙浉鍏炽
路 鍙兘鏄粰瀹氱被鍨嬬殑缁撴瀯寮忓彉閲忕殑鍑犱釜瀹炰緥銆傛瘡涓疄渚嬫湁涓涓笉鍚岀殑鍚嶏紝鎸囧悜鏈嶅姟鍣ㄧ淮鎶ょ殑涓嶅悓鐨勮祫婧愩
MySQL 5.1鏀寔缁撴瀯寮忓彉閲忕被鍨嬶紝鍙互鎸囧畾鐩戞帶閿肩紦瀛樻搷浣滅殑鍙傛暟銆傞敭鍊肩紦瀛樼粨鏋勫紡鍙橀噺鏈変互涓嬬粍浠讹細
路 key_buffer_size
路 key_cache_block_size
路 key_cache_division_limit
路 key_cache_age_threshold
璇ヨ妭鎻忚堪浜嗗紩鐢ㄧ粨鏋勫紡鍙橀噺鐨勮娉曘傚湪璇硶鐨勪緥瀛愪腑浣跨敤浜嗛敭鍊肩紦瀛樺彉閲忥紝浣嗗叧浜庨敭鍊肩紦瀛樺浣曟搷浣滅殑鍏蜂綋璇︽儏鍦ㄥ叾瀹冪珷鑺備腑锛屽 7.4.6鑺傦紝鈥淢yISAM閿珮閫熺紦鍐测銆
瑕佸紩鐢ㄧ粨鏋勫紡鍙橀噺瀹炰緥鐨勭粍浠讹紝鍙互浣跨敤instance_name.component_name鏍煎紡鐨勫鍚堝悕銆備緥濡傦細
hot_cache.key_buffer_size
hot_cache.key_cache_block_size
cold_cache.key_cache_block_size
瀵逛簬姣忎釜缁撴瀯寮忕郴缁熷彉閲忥紝鎬绘槸棰勫畾涔夊悕涓default鐨勪竴涓疄渚嬨傚鏋滀笉浣跨敤浠讳綍瀹炰緥鍚嶅紩鐢ㄧ粨鏋勫紡鍙橀噺鐨勪竴涓粍浠讹紝default瀹炰緥琚娇鐢ㄣ傝繖鏍凤紝default.key_buffer_size鍜key_buffer_sizeboth鍧囨寚鍚戝悓涓绯荤粺鍙橀噺銆
缁撴瀯寮忓彉閲忓疄渚嬪拰缁勪欢鐨勫懡鍚嶈鍒欎负锛
路 瀵逛簬缁欏畾绫诲瀷鐨勭粨鏋勫紡鍙橀噺锛屾瘡涓疄渚嬪繀椤绘湁涓涓湪璇ョ被鍙橀噺涓敮涓鐨勪竴涓悕銆備絾鏄紝鍦ㄤ笉鍚岀被鍨嬬殑缁撴瀯寮忓彉閲忎腑瀹炰緥鍚嶄笉闇瑕佸敮涓銆備緥濡傦紝姣忎釜缁撴瀯寮忓彉閲忔湁涓涓疄渚default锛屽洜姝ゅ湪涓嶅悓鐨勫彉閲忕被鍨嬩腑default涓嶆槸鍞竴鐨勩
路 姣忎釜缁撴瀯寮忓彉閲忕被鍨嬬殑缁勪欢鍚嶅湪鎵鏈夌郴缁熷彉閲忓悕涓繀椤绘槸鍞竴鐨勩傚鏋滀笉鏄繖鏍(涔熷氨鏄锛屽鏋滀袱涓笉鍚岀被鍨嬬殑缁撴瀯寮忓彉閲忚兘澶熷叡浜粍浠舵垚鍛樺悕)锛屽皢涓嶆竻妤氫娇鐢ㄥ摢涓粯璁ょ粨鏋勫紡鍙橀噺鏉ョ敤浣滄病鏈変娇鐢ㄥ疄渚嬪悕闄愬畾鐨勬垚鍛樺悕銆
路 濡傛灉缁撴瀯寮忓彉閲忓疄渚嬪悕浣滀负鏈紩璧锋潵鐨勮瘑鍒涓嶅悎娉曪紝灏嗗畠鐢ㄥ弽鍕惧彿寮曡捣鏉ヤ綔涓鸿瘑鍒銆備緥濡傦紝hot-cache涓嶅悎娉曪紝浣`hot-cache` 鍚堟硶銆
路 global銆session鍜local涓嶆槸鍚堟硶瀹炰緥鍚嶃傝繖鏍峰彲浠ラ伩鍏嶄笌寮曠敤闈炵粨鏋勫紡绯荤粺鍙橀噺鐨勭鍙风殑鍐茬獊锛屼緥濡@@global.var_name銆
鐩墠锛岃繖鍓嶄袱涓鍒欎笉鍙兘杩濊儗锛屽洜涓哄敮涓鐨勭粨鏋勫紡鍙橀噺绫诲瀷鏄敭鍊肩紦瀛樸傚湪灏嗘潵鍒涘缓鍏跺畠绫诲瀷鐨勭粨鏋勫紡鍙橀噺锛岃繖浜涜鍒欏皢鏈夐噸瑕佺殑鎰忎箟銆
涓涓緥澶栨槸锛屽彲浠ュ湪鍙兘鍑虹幇绠鍗曞彉閲忓悕鐨勪笂涓嬫枃涓娇鐢ㄥ鍚堝悕寮曠敤缁撴瀯寮忓彉閲忕粍浠躲備緥濡傦紝鍙互浣跨敤涓涓懡浠よ閫夐」鏈煇涓粨鏋勫紡鍙橀噺鍒嗛厤涓涓硷細
shell> mysqld --hot_cache.key_buffer_size=64K
鍦ㄩ夐」鏂囦欢涓紝浣跨敤锛
[mysqld]
hot_cache.key_buffer_size=64K
濡傛灉鐢ㄨ閫夐」鍚姩鏈嶅姟鍣紝闄や簡榛樿澶у皬涓8MB鐨勯粯璁ら敭鍊肩紦瀛橈紝杩樺垱寤轰竴涓悕涓hot_cache鐨勯敭鍊肩紦瀛橈紝澶у皬涓64KB銆
鍋囧畾浣犺繖鏍峰惎鍔ㄦ湇鍔″櫒锛
shell> mysqld --key_buffer_size=256K \
--extra_cache.key_buffer_size=128K \
--extra_cache.key_cache_block_size=2048
鍦ㄨ繖绉嶆儏鍐典笅锛屾湇鍔″櫒灏嗛粯璁ら敭鍊肩紦瀛樼殑澶у皬璁惧畾涓256KB銆(涔熷彲浠ュ啓鎴--default.key_buffer_size=256K锛銆 骞朵笖锛屾湇鍔″櫒鍒涘缓涓涓悕涓extra_cache鐨勭2涓敭鍊肩紦瀛橈紝澶у皬涓128KB锛岀紦瀛樿〃绱㈠紩鍧楃殑鍧楃紦瀛樺尯鐨勫ぇ灏忚缃负2048瀛楄妭銆
鍦ㄤ笅闈㈢殑渚嬪瓙涓紝鐢3涓笉鍚岀殑閿肩紦瀛橈紙澶у皬姣斾緥涓3:1:1锛夊惎鍔ㄦ湇鍔″櫒锛
shell> mysqld --key_buffer_size=6M \
--hot_cache.key_buffer_size=2M \
--cold_cache.key_buffer_size=2M
涔熷彲浠ュ湪杩愯鏃惰缃拰妫绱㈢粨鏋勫紡鍙橀噺鍊笺備緥濡傦紝瑕佹兂灏嗗悕涓hot_cache鐨勪竴涓敭鍊肩紦瀛樼殑澶у皬璁剧疆涓10MB锛屼娇鐢ㄤ笅闈换浣曚竴涓鍙ワ細
mysql> SET GLOBAL hot_cache.key_buffer_size = 10*1024*1024;
mysql> SET @@global.hot_cache.key_buffer_size = 10*1024*1024;
瑕佹兂妫绱㈢紦瀛樺ぇ灏忥紝鎵ц锛
mysql> SELECT @@global.hot_cache.key_buffer_size;
浣嗘槸锛屼笅闈㈢殑璇彞涓嶅伐浣溿傚彉閲忎笉瑙i噴涓轰竴涓鍚堝悕锛岃屾槸瑙i噴涓LIKE妯″紡鍖归厤鎿嶄綔鐨勭畝鍗曞瓧绗︿覆锛
mysql> SHOW GLOBAL VARIABLES LIKE 'hot_cache.key_buffer_size';
杩欐槸涓涓湪鍙兘鍑虹幇绠鍗曠殑鍙橀噺鍚嶆椂浣跨敤缁撴瀯寮忓彉閲忓悕鐨勪緥瀛愩
MySQL鏈嶅姟鍣ㄦ敮鎸3绉嶆敞閲婇鏍硷細
路 浠庘#鈥欏瓧绗︿粠琛屽熬銆
路 浠庘-- 鈥欏簭鍒楀埌琛屽熬銆傝娉ㄦ剰鈥-- 鈥(鍙岀牬鎶樺彿)娉ㄩ噴椋庢牸瑕佹眰绗2涓牬鎶樺彿鍚庨潰鑷冲皯璺熶竴涓┖鏍肩(渚嬪绌烘牸銆tab銆佹崲琛岀绛夌瓑)銆傝璇硶涓庢爣鍑SQL娉ㄩ噴璇硶绋嶆湁涓嶅悓锛屽悗鑰呭皢鍦1.8.5.7, 鈥溾--鈥欎綔涓烘敞閲婅捣濮嬫爣璁扳涓璁恒
路 浠/*搴忓垪鍒板悗闈㈢殑*/搴忓垪銆傜粨鏉熷簭鍒椾笉涓瀹氬湪鍚屼竴琛屼腑锛屽洜姝よ璇硶鍏佽娉ㄩ噴璺ㄨ秺澶氳銆
涓嬮潰鐨勪緥瀛愭樉绀轰簡3绉嶉鏍肩殑娉ㄩ噴锛
mysql> SELECT 1+1; # This comment continues to the end of line
mysql> SELECT 1+1; -- This comment continues to the end of line
mysql> SELECT 1 /* this is an in-line comment */ + 1;
mysql> SELECT 1+
/*
this is a
multiple-line comment
*/
1;
涓婅堪鐨勬敞閲婅娉曢傜敤浜mysqld鏈嶅姟鍣ㄥ浣曞垎鏋SQL璇彞銆傚彂閫佸埌鏈嶅姟鍣ㄤ箣鍓嶏紝mysql瀹㈡埛绋嬪簭涔熸墽琛岄儴鍒嗚鍙ヨВ鏋愩(渚嬪锛屽畠閫氳繃瑙f瀽鏉ョ‘瀹氬湪澶氳鍙ヨ涓殑璇彞杈圭晫锛銆
鍦MySQL 5.1涓紝mysql瑙f瀽/* ...*/娉ㄩ噴鐨勫敮涓灞闄愭ф槸缁撳悎璇ラ鏍肩殑娉ㄩ噴瀹氱晫绗︿娇鐢ㄧ殑鍙瑰彿鏍囪浜嗘湁鏉′欢鎵ц鐨SQL璇彞閮ㄥ垎銆傞傜敤浜庝氦浜掑紡杩愯mysql鍜屽皢鍛戒护鏀惧叆涓涓枃浠朵腑锛屽苟浠ユ壒澶勭悊妯″紡浣跨敤mysql鏉ュ鐞mysql < file_name鐨勬枃浠躲傝缁嗕俊鎭拰渚嬪瓙鍙傝1.8.4鑺傦紝鈥淢ySQL瀵规爣鍑哠QL鐨勬墿灞曗銆
灏濊瘯浣跨敤涓涓瘑鍒锛屼緥濡備娇鐢ㄥ祵鍏ュ紡MySQL鏁版嵁绫诲瀷鎴栧嚱鏁板悕浣滀负琛ㄥ悕鎴栧垪鍚嶏紝渚嬪TIMESTAMP鎴GROUP锛屼細閫犳垚涓涓父瑙侀棶棰樸傚厑璁镐綘杩欐牱鎿嶄綔(渚嬪锛ABS鍙互浣滀负涓涓垪鍚)銆備絾鏄紝榛樿鎯呭喌涓嬶紝鍦ㄦ暟璋冪敤涓湪鍑芥暟鍚嶅拰鍚庨潰鐨勨(鈥欏瓧绗︿箣闂翠笉鍏佽鏈夌┖鏍笺傝瑕佹眰浣垮嚱鏁拌皟鐢ㄤ笌鍒楀悕寮曠敤涓嶅悓銆
璇ヨ涓虹殑涓嶅埄缁撴灉鏄湪鏌愪簺涓婁笅鏂囦腑鐪佺暐涓涓┖鏍间細浣胯瘑鍒瑙i噴涓哄嚱鏁板悕銆備緥濡傦紝璇ヨ鍙ュ悎娉曪細
mysql> CREATE TABLE abs (val INT)锛
浣嗙渷鐣abs鍚庨潰鐨勭┖鏍间細閫犳垚璇硶閿欒锛屽洜涓虹渷鐣ュ悗璇ヨ鍙ュソ鍍忚璋冪敤ABS()鍑芥暟锛
mysql> CREATE TABLE abs(val INT);
濡傛灉SQL鏈嶅姟鍣ㄦā寮忓寘鎷IGNORE_SPACE妯″紡鍊硷紝鏈嶅姟鍣ㄥ厑璁稿嚱鏁拌皟鐢ㄦ椂鍦ㄥ嚱鏁板悕鍜屽悗闈㈢殑鈥(鈥欏瓧绗︿箣闂存湁绌烘牸銆傝繖鏍蜂娇鍑芥暟鍚嶈瑙嗕负淇濈暀瀛椼傜粨鏋滄槸锛屼笌鍑芥暟鍚嶇浉鍚岀殑璇嗗埆绗﹀繀椤绘寜鐓9.2鑺傦紝鈥滄暟鎹簱銆佽〃銆佺储寮曘佸垪鍜屽埆鍚嶁涓墍鎻忚堪鐨勫紩璧锋潵銆SQL鏈嶅姟鍣ㄦā寮忔寜鐓5.3.2鑺傦紝鈥淪QL鏈嶅姟鍣ㄦā寮忊涓墍鎻忚堪鐨勮繘琛屾帶鍒躲
闄愬畾鍚嶄腑鍙ョ偣鍚庨潰鐨勫瓧蹇呴』涓轰竴涓瘑鍒锛屽洜姝や笉闇瑕佸皢瀹冨紩璧锋潵锛屽嵆浣垮畠鏄竴涓繚鐣欏瓧銆
鍦MySQL涓紝涓嬭〃涓殑瀛楁樉寮忚淇濈暀銆傚叾涓ぇ澶氭暟瀛楄繘鍒惰鏍囧噯SQL鐢ㄤ綔鍒楀悕鍜/鎴栬〃鍚(渚嬪锛GROUP)銆傚皯鏁拌淇濈暀浜嗭紝鍥犱负MySQL闇瑕佸畠浠紝(鐩墠)浣跨敤yacc瑙f瀽绋嬪簭銆備繚鐣欏瓧琚紩璧锋潵鍚庡彲浠ョ敤浣滆瘑鍒銆
ADD | ALL | ALTER |
ANALYZE | AND | AS |
ASC | ASENSITIVE | BEFORE |
BETWEEN | BIGINT | BINARY |
BLOB | BOTH | BY |
CALL | CASCADE | CASE |
CHANGE | CHAR | CHARACTER |
CHECK | COLLATE | COLUMN |
CONDITION | CONNECTION | CONSTRAINT |
CONTINUE | CONVERT | CREATE |
CROSS | CURRENT_DATE | CURRENT_TIME |
CURRENT_TIMESTAMP | CURRENT_USER | CURSOR |
DATABASE | DATABASES | DAY_HOUR |
DAY_MICROSECOND | DAY_MINUTE | DAY_SECOND |
DEC | DECIMAL | DECLARE |
DEFAULT | DELAYED | DELETE |
DESC | DESCRIBE | DETERMINISTIC |
DISTINCT | DISTINCTROW | DIV |
DOUBLE | DROP | DUAL |
EACH | ELSE | ELSEIF |
ENCLOSED | ESCAPED | EXISTS |
EXIT | EXPLAIN | FALSE |
FETCH | FLOAT | FLOAT4 |
FLOAT8 | FOR | FORCE |
FOREIGN | FROM | FULLTEXT |
GOTO | GRANT | GROUP |
HAVING | HIGH_PRIORITY | HOUR_MICROSECOND |
HOUR_MINUTE | HOUR_SECOND | IF |
IGNORE | IN | INDEX |
INFILE | INNER | INOUT |
INSENSITIVE | INSERT | INT |
INT1 | INT2 | INT3 |
INT4 | INT8 | INTEGER |
INTERVAL | INTO | IS |
ITERATE | JOIN | KEY |
KEYS | KILL | LABEL |
LEADING | LEAVE | LEFT |
LIKE | LIMIT | LINEAR |
LINES | LOAD | LOCALTIME |
LOCALTIMESTAMP | LOCK | LONG |
LONGBLOB | LONGTEXT | LOOP |
LOW_PRIORITY | MATCH | MEDIUMBLOB |
MEDIUMINT | MEDIUMTEXT | MIDDLEINT |
MINUTE_MICROSECOND | MINUTE_SECOND | MOD |
MODIFIES | NATURAL | NOT |
NO_WRITE_TO_BINLOG | NULL | NUMERIC |
ON | OPTIMIZE | OPTION |
OPTIONALLY | OR | ORDER |
OUT | OUTER | OUTFILE |
PRECISION | PRIMARY | PROCEDURE |
PURGE | RAID0 | RANGE |
READ | READS | REAL |
REFERENCES | REGEXP | RELEASE |
RENAME | REPEAT | REPLACE |
REQUIRE | RESTRICT | RETURN |
REVOKE | RIGHT | RLIKE |
SCHEMA | SCHEMAS | SECOND_MICROSECOND |
SELECT | SENSITIVE | SEPARATOR |
SET | SHOW | SMALLINT |
SPATIAL | SPECIFIC | SQL |
SQLEXCEPTION | SQLSTATE | SQLWARNING |
SQL_BIG_RESULT | SQL_CALC_FOUND_ROWS | SQL_SMALL_RESULT |
SSL | STARTING | STRAIGHT_JOIN |
TABLE | TERMINATED | THEN |
TINYBLOB | TINYINT | TINYTEXT |
TO | TRAILING | TRIGGER |
TRUE | UNDO | UNION |
UNIQUE | UNLOCK | UNSIGNED |
UPDATE | USAGE | USE |
USING | UTC_DATE | UTC_TIME |
UTC_TIMESTAMP | VALUES | VARBINARY |
VARCHAR | VARCHARACTER | VARYING |
WHEN | WHERE | WHILE |
WITH | WRITE | X509 |
XOR | YEAR_MONTH | ZEROFILL |
MySQL鍏佽閮ㄥ垎鍏抽敭瀛楃敤鍋氭湭寮曡捣鏉ョ殑璇嗗埆绗︼紝鍥犱负璁稿浜轰互鍓嶆浘浣跨敤杩囧畠浠備笅闈㈠垪鍑轰簡涓浜涗緥瀛愶細
ACTION
BIT
DATE
ENUM
NO
TEXT
TIME
TIMESTAMP
杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com.銆傚師濮嬪弬鑰冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆