1.MySQL鏄竴涓叧绯诲瀷鏁版嵁搴撶鐞嗙郴缁燂紝鐢辩憺鍏窶ySQL AB 鍏徃寮�鍙戯紝鐩墠灞炰簬 Oracle 鏃椾笅浜у搧銆侻ySQL 鏈�娴佽鐨勫叧绯诲瀷鏁版嵁搴撶鐞嗙郴缁燂紝鍦� WEB 搴旂敤鏂归潰MySQL鏄渶濂界殑 RDBMS (Relational Database Management System锛屽叧绯绘暟鎹簱绠$悊绯荤粺) 搴旂敤杞欢涔嬩竴銆�
MySQL鏄竴绉嶅叧鑱旀暟鎹簱绠$悊绯荤粺锛屽叧鑱旀暟鎹簱灏嗘暟鎹繚瀛樺湪涓嶅悓鐨勮〃涓紝鑰屼笉鏄皢鎵�鏈夋暟鎹斁鍦ㄤ竴涓ぇ浠撳簱鍐咃紝杩欐牱灏卞鍔犱簡閫熷害骞舵彁楂樹簡鐏垫椿鎬с��
MySQL鎵�浣跨敤鐨� SQL 璇█鏄敤浜庤闂暟鎹簱鐨勬渶甯哥敤鏍囧噯鍖栬瑷�銆侻ySQL 杞欢閲囩敤浜嗗弻鎺堟潈鏀跨瓥锛屽畠鍒嗕负绀惧尯鐗堝拰鍟嗕笟鐗堬紝鐢变簬鍏朵綋绉皬銆侀�熷害蹇�佹�讳綋鎷ユ湁鎴愭湰浣庯紝灏ゅ叾鏄紑鏀炬簮鐮佽繖涓�鐗圭偣锛屼竴鑸腑灏忓瀷缃戠珯鐨勫紑鍙戦兘閫夋嫨 MySQL 浣滀负缃戠珯鏁版嵁搴撱��
鐢变簬鍏剁ぞ鍖虹増鐨勬�ц兘鍗撹秺锛屾惌閰� PHP 鍜� Apache 鍙粍鎴愯壇濂界殑寮�鍙戠幆澧冦�俒1]
澶栨枃鍚� MySQL 绫宦� 聽 鍨嬪叧绯诲瀷鏁版嵁搴撶鐞嗙郴缁� 鎵�聽 聽 灞濷racle[2]聽 寮�鍙戝叕鍙� 鐟炲吀MySQL AB 鍏徃
聽 聽 渚嬪 Oracle銆丏B2銆丼QL Server绛夌浉姣旓紝MySQL 鑷湁瀹冪殑涓嶈冻涔嬪锛屼絾鏄繖涓濇涔熸病鏈夊噺灏戝畠鍙楁杩庣殑绋嬪害銆傚浜庝竴鑸殑涓汉浣跨敤鑰呭拰涓皬鍨嬩紒涓氭潵璇达紝MySQL鎻愪緵鐨勫姛鑳藉凡缁忕话缁版湁浣欙紝鑰屼笖鐢变簬 MySQ L鏄紑鏀炬簮鐮佽蒋浠讹紝鍥犳鍙互澶уぇ闄嶄綆鎬讳綋鎷ユ湁鎴愭湰銆�
Linux浣滀负鎿嶄綔绯荤粺锛孉pache鍜� Nginx浣滀负 Web 鏈嶅姟鍣紝MySQL 浣滀负鏁版嵁搴擄紝PHP/Perl/Python浣滀负鏈嶅姟鍣ㄧ鑴氭湰瑙i噴鍣ㄣ�傜敱浜庤繖鍥涗釜杞欢閮芥槸鍏嶈垂鎴栧紑鏀炬簮鐮佽蒋浠讹紙FLOSS)锛屽洜姝や娇鐢ㄨ繖绉嶆柟寮忎笉鐢ㄨ姳涓�鍒嗛挶锛堥櫎寮�浜哄伐鎴愭湰锛夊氨鍙互寤虹珛璧蜂竴涓ǔ瀹氥�佸厤璐圭殑缃戠珯绯荤粺锛岃涓氱晫绉颁负鈥淟AMP鈥滄垨鈥淟NMP鈥濈粍鍚圼3]聽 銆�
绯荤粺鐗规�х紪杈�
1锛庝娇鐢� C鍜� C++缂栧啓锛屽苟浣跨敤浜嗗绉嶇紪璇戝櫒杩涜娴嬭瘯锛屼繚璇佷簡婧愪唬鐮佺殑鍙Щ妞嶆�с��
2锛庢敮鎸� AIX銆丗reeBSD銆丠P-UX銆丩inux銆丮ac OS銆丯ovellNetware銆丱penBSD銆丱S/2 Wrap銆丼olaris銆乄indows绛夊绉嶆搷浣滅郴缁熴��
3锛庝负澶氱缂栫▼璇█鎻愪緵浜� API銆傝繖浜涚紪绋嬭瑷�鍖呮嫭 C銆丆++銆丳ython銆丣ava銆丳erl銆丳HP銆丒iffel銆丷uby,.NET鍜� Tcl 绛夈��
4锛庢敮鎸佸绾跨▼锛屽厖鍒嗗埄鐢� CPU 璧勬簮銆�
5锛庝紭鍖栫殑 SQL鏌ヨ绠楁硶锛屾湁鏁堝湴鎻愰珮鏌ヨ閫熷害銆�
6锛庢棦鑳藉浣滀负涓�涓崟鐙殑搴旂敤绋嬪簭搴旂敤鍦ㄥ鎴风鏈嶅姟鍣ㄧ綉缁滅幆澧冧腑锛屼篃鑳藉浣滀负涓�涓簱鑰屽祵鍏ュ埌鍏朵粬鐨勮蒋浠朵腑銆�
7锛庢彁渚涘璇█鏀寔锛屽父瑙佺殑缂栫爜濡備腑鏂囩殑 GB 2312銆丅IG5锛屾棩鏂囩殑 Shift_JIS绛夐兘鍙互鐢ㄤ綔鏁版嵁琛ㄥ悕鍜屾暟鎹垪鍚嶃��
8锛庢彁渚� TCP/IP銆丱DBC 鍜� JDBC绛夊绉嶆暟鎹簱杩炴帴閫斿緞銆�
9锛庢彁渚涚敤浜庣鐞嗐�佹鏌ャ�佷紭鍖栨暟鎹簱鎿嶄綔鐨勭鐞嗗伐鍏枫��
10锛庢敮鎸佸ぇ鍨嬬殑鏁版嵁搴撱�傚彲浠ュ鐞嗘嫢鏈変笂鍗冧竾鏉¤褰曠殑澶у瀷鏁版嵁搴撱��
11锛庢敮鎸佸绉嶅瓨鍌ㄥ紩鎿庛��
12.MySQL 鏄紑婧愮殑锛屾墍浠ヤ綘涓嶉渶瑕佹敮浠橀澶栫殑璐圭敤銆�
13.MySQL 浣跨敤鏍囧噯鐨� SQL鏁版嵁璇█褰㈠紡銆�
14.MySQL 瀵� PHP 鏈夊緢濂界殑鏀寔锛孭HP鏄洰鍓嶆渶娴佽鐨� Web 寮�鍙戣瑷�銆�
15.MySQL鏄彲浠ュ畾鍒剁殑锛岄噰鐢ㄤ簡 GPL鍗忚锛屼綘鍙互淇敼婧愮爜鏉ュ紑鍙戣嚜宸辩殑 MySQL 绯荤粺銆�
16.鍦ㄧ嚎 DDL/鏇存敼鍔熻兘锛屾暟鎹灦鏋勬敮鎸佸姩鎬佸簲鐢ㄧ▼搴忓拰寮�鍙戜汉鍛樼伒娲绘�э紙5.6[4]聽 鏂板锛�
17.澶嶅埗鍏ㄥ眬浜嬪姟鏍囪瘑锛屽彲鏀寔鑷垜淇寮忛泦缇わ紙5.6[4]聽 鏂板锛�
18.澶嶅埗鏃犲穿婧冧粠鏈猴紝鍙彁楂樺彲鐢ㄦ�э紙5.6[4]聽 鏂板锛�
19.澶嶅埗澶氱嚎绋嬩粠鏈猴紝鍙彁楂樻�ц兘锛�5.6[4]聽 鏂板锛�
瀛樺偍寮曟搸缂栬緫
MyISAMMySQL 5.0 涔嬪墠鐨勯粯璁ゆ暟鎹簱寮曟搸锛屾渶涓哄父鐢ㄣ�傛嫢鏈夎緝楂樼殑鎻掑叆锛屾煡璇㈤�熷害锛屼絾涓嶆敮鎸佷簨鍔�
InnoDB浜嬪姟鍨嬫暟鎹簱鐨勯閫夊紩鎿庯紝鏀寔ACID浜嬪姟锛屾敮鎸佽绾ч攣瀹�, MySQL 5.5 璧锋垚涓洪粯璁ゆ暟鎹簱寮曟搸
BDB婧� 鑷� Berkeley DB锛屼簨鍔″瀷鏁版嵁搴撶殑鍙︿竴绉嶉�夋嫨锛屾敮鎸丆ommit 鍜孯ollback 绛夊叾浠栦簨鍔$壒鎬�
Memory鎵�鏈夋暟鎹疆浜庡唴瀛樼殑瀛樺偍寮曟搸锛屾嫢鏈夋瀬楂樼殑鎻掑叆锛屾洿鏂板拰鏌ヨ鏁堢巼銆備絾鏄細鍗犵敤鍜屾暟鎹噺鎴愭姣旂殑鍐呭瓨绌洪棿銆傚苟涓斿叾鍐呭浼氬湪 MySQL 閲嶆柊鍚姩鏃朵涪澶�
Merge灏嗕竴瀹氭暟閲忕殑 MyISAM 琛ㄨ仈鍚堣�屾垚涓�涓暣浣擄紝鍦ㄨ秴澶ц妯℃暟鎹瓨鍌ㄦ椂寰堟湁鐢�
Archive闈炲父閫傚悎瀛樺偍澶ч噺鐨勭嫭绔嬬殑锛屼綔涓哄巻鍙茶褰曠殑鏁版嵁銆傚洜涓哄畠浠笉缁忓父琚鍙栥�侫rchive 鎷ユ湁楂樻晥鐨勬彃鍏ラ�熷害锛屼絾鍏跺鏌ヨ鐨勬敮鎸佺浉瀵硅緝宸�
Federated灏嗕笉鍚岀殑 MySQL 鏈嶅姟鍣ㄨ仈鍚堣捣鏉ワ紝閫昏緫涓婄粍鎴愪竴涓畬鏁寸殑鏁版嵁搴撱�傞潪甯搁�傚悎鍒嗗竷寮忓簲鐢�
Cluster/NDB楂樺啑浣欑殑瀛樺偍寮曟搸锛岀敤澶氬彴鏁版嵁鏈哄櫒鑱斿悎鎻愪緵鏈嶅姟浠ユ彁楂樻暣浣撴�ц兘鍜屽畨鍏ㄦ�с�傞�傚悎鏁版嵁閲忓ぇ锛屽畨鍏ㄥ拰鎬ц兘瑕佹眰楂樼殑搴旂敤
CSV锛� 閫昏緫涓婄敱閫楀彿鍒嗗壊鏁版嵁鐨勫瓨鍌ㄥ紩鎿庛�傚畠浼氬湪鏁版嵁搴撳瓙鐩綍閲屼负姣忎釜鏁版嵁琛ㄥ垱寤轰竴涓� .csv 鏂囦欢銆傝繖鏄竴绉嶆櫘閫氭枃鏈枃浠讹紝姣忎釜鏁版嵁琛屽崰鐢ㄤ竴涓枃鏈銆侰SV 瀛樺偍寮曟搸涓嶆敮鎸佺储寮曘��
BlackHole锛氶粦娲炲紩鎿庯紝鍐欏叆鐨勪换浣曟暟鎹兘浼氭秷澶憋紝涓�鑸敤浜庤褰� binlog 鍋氬鍒剁殑涓户
EXAMPLE 瀛樺偍寮曟搸鏄竴涓笉鍋氫换浣曚簨鎯呯殑瀛樻牴寮曟搸銆傚畠鐨勭洰鐨勬槸浣滀负 MySQL 婧愪唬鐮佷腑鐨勪竴涓緥瀛愶紝鐢ㄦ潵婕旂ず濡備綍寮�濮嬬紪鍐欎竴涓柊瀛樺偍寮曟搸銆傚悓鏍凤紝瀹冪殑涓昏鍏磋叮鏄寮�鍙戣�呫�侲XAMPLE 瀛樺偍寮曟搸涓嶆敮鎸佺紪绱㈠紩銆�
鍙﹀锛孧ySQL 鐨勫瓨鍌ㄥ紩鎿庢帴鍙e畾涔夎壇濂姐�傛湁鍏磋叮鐨勫紑鍙戣�呭彲浠ラ�氳繃闃呰鏂囨。缂栧啓鑷繁鐨勫瓨鍌ㄥ紩鎿庛��
绱㈠紩鍔熻兘缂栬緫
绱㈠紩鏄竴绉嶇壒娈婄殑鏂囦欢锛圛nnoDB 鏁版嵁琛ㄤ笂鐨勭储寮曟槸琛ㄧ┖闂寸殑涓�涓粍鎴愰儴鍒嗭級锛屽畠浠寘鍚潃瀵规暟鎹〃閲屾墍鏈夎褰曠殑寮曠敤鎸囬拡銆傜储寮曚笉鏄竾鑳界殑锛岀储寮曞彲浠ュ姞蹇暟鎹绱㈡搷浣滐紝浣嗕細浣挎暟鎹慨鏀规搷浣滃彉鎱€�傛瘡淇敼鏁版嵁璁板綍锛岀储寮曞氨蹇呴』鍒锋柊涓�娆°�備负浜嗗湪鏌愮绋嬪害涓婂讥琛ヨ繖涓�缂洪櫡锛岃澶� SQL 鍛戒护閮芥湁涓�涓� DELAY_KEY_WRITE 椤广�傝繖涓�夐」鐨勪綔鐢ㄦ槸鏆傛椂鍒舵 MySQL 鍦ㄨ鍛戒护姣忔彃鍏ヤ竴鏉℃柊璁板綍鍜屾瘡淇敼涓�鏉$幇鏈変箣鍚庣珛鍒诲绱㈠紩杩涜鍒锋柊锛屽绱㈠紩鐨勫埛鏂板皢绛夊埌鍏ㄩ儴璁板綍鎻掑叆/淇敼瀹屾瘯涔嬪悗鍐嶈繘琛屻�傚湪闇�瑕佹妸璁稿鏂拌褰曟彃鍏ユ煇涓暟鎹〃鐨勫満鍚堬紝DELAY_KEY_WRITE 閫夐」鐨勪綔鐢ㄥ皢闈炲父鏄庢樉銆傚彟澶栵紝绱㈠紩杩樹細鍦ㄧ‖鐩樹笂鍗犵敤鐩稿綋澶х殑绌洪棿銆傚洜姝ゅ簲璇ュ彧涓烘渶缁忓父鏌ヨ鍜屾渶缁忓父鎺掑簭鐨勬暟鎹垪寤虹珛绱㈠紩銆傛敞鎰忥紝濡傛灉鏌愪釜鏁版嵁鍒楀寘鍚澶氶噸澶嶇殑鍐呭锛屼负瀹冨缓绔嬬储寮曞氨娌℃湁澶ぇ鐨勫疄闄呮晥鏋溿��
浠庣悊璁轰笂璁诧紝瀹屽叏鍙互涓烘暟鎹〃閲岀殑姣忎釜瀛楁鍒嗗埆寤轰竴涓储寮曪紝浣� MySQL 鎶婂悓涓�涓暟鎹〃閲岀殑绱㈠紩鎬绘暟闄愬埗涓�16涓��
1锛嶪nnoDB 鏁版嵁琛ㄧ殑绱㈠紩
涓� InnoDB鏁版嵁琛ㄧ浉姣旓紝鍦� InnoDB 鏁版嵁琛ㄤ笂锛岀储寮曞 InnoDB 鏁版嵁琛ㄧ殑閲嶈鎬ц澶у緱澶氥�傚湪 InnoDB 鏁版嵁琛ㄤ笂锛岀储寮曚笉浠呬細鍦ㄦ悳绱㈡暟鎹褰曟椂鍙戞尌浣滅敤锛岃繕鏄暟鎹绾ч攣瀹氭満鍒剁殑鑻娿�佸熀纭�銆傗�滄暟鎹绾ч攣瀹氣�濈殑鎰忔�濇槸鎸囧湪浜嬪姟鎿嶄綔鐨勬墽琛岃繃绋嬩腑閿佸畾姝e湪琚鐞嗙殑涓埆璁板綍锛屼笉璁╁叾浠栫敤鎴疯繘琛岃闂�傝繖绉嶉攣瀹氬皢褰卞搷鍒帮紙浣嗕笉闄愪簬锛塖ELECT銆丩OCKINSHAREMODE銆丼ELECT銆丗ORUPDATE 鍛戒护浠ュ強 INSERT銆乁PDATE 鍜� DELETE 鍛戒护銆傚嚭浜庢晥鐜囨柟闈㈢殑鑰冭檻锛孖nnoDB 鏁版嵁琛ㄧ殑鏁版嵁琛岀骇閿佸畾瀹為檯鍙戠敓鍦ㄥ畠浠殑绱㈠紩涓婏紝鑰屼笉鏄暟鎹〃鑷韩涓娿�傛樉鐒讹紝鏁版嵁琛岀骇閿佸畾鏈哄埗鍙湁鍦ㄦ湁鍏崇殑鏁版嵁琛ㄦ湁涓�涓悎閫傜殑绱㈠紩鍙緵閿佸畾鐨勬椂鍊欐墠鑳藉彂鎸ユ晥鍔涖��
2锛庨檺鍒�
濡傛灉 WHERE 瀛愬彞鐨勬煡璇㈡潯浠堕噷鏈変笉绛夊彿锛圵HERE coloum !=锛夛紝MySQL 灏嗘棤娉曚娇鐢ㄧ储寮曘�傜被浼煎湴锛屽鏋� WHERE 瀛愬彞鐨勬煡璇㈡潯浠堕噷浣跨敤浜嗗嚱鏁帮紙WHERE DAY锛坈olumn锛�=锛夛紝MySQL 涔熷皢鏃犳硶浣跨敤绱㈠紩銆傚湪 JOIN 鎿嶄綔涓紙闇�瑕佷粠澶氫釜鏁版嵁琛ㄦ彁鍙栨暟鎹椂锛夛紝MySQL 鍙湁鍦ㄤ富閿拰澶栭敭鐨勬暟鎹被鍨嬬浉鍚屾椂鎵嶈兘浣跨敤绱㈠紩銆�
濡傛灉 WHERE 瀛愬彞鐨勬煡璇㈡潯浠堕噷浣跨敤姣旇緝鎿嶄綔绗� LIKE 鍜� REGEXP锛孧ySQL 鍙湁鍦ㄦ悳绱㈡ā鏉跨殑绗竴涓瓧绗︿笉鏄�氶厤绗︾殑鎯呭喌涓嬫墠鑳戒娇鐢ㄧ储寮曘�傛瘮濡傝锛屽鏋滄煡璇㈡潯浠舵槸 LIKE 'abc%鈥橈紝MySQL 灏嗕娇鐢ㄧ储寮曪紱濡傛灉鏌ヨ鏉′欢鏄� LIKE '%abc鈥欙紝MySQL 灏嗕笉浣跨敤绱㈠紩銆�
鍦� ORDER BY 鎿嶄綔涓紝MySQL 鍙湁鍦ㄦ帓搴忔潯浠朵笉鏄竴涓煡璇㈡潯浠惰〃杈惧紡鐨勬儏鍐典笅鎵嶄娇鐢ㄧ储寮曘�傦紙铏界劧濡傛锛屽湪娑夊強澶氫釜鏁版嵁琛ㄦ煡璇㈤噷锛屽嵆浣挎湁绱㈠紩鍙敤锛岄偅浜涚储寮曞湪鍔犲揩 ORDER BY 鏂归潰涔熸病浠�涔堜綔鐢級銆傚鏋滄煇涓暟鎹垪閲屽寘鍚澶氶噸澶嶇殑鍊硷紝灏辩畻涓哄畠寤虹珛浜嗙储寮曚篃涓嶄細鏈夊緢濂界殑鏁堟灉銆傛瘮濡傝锛屽鏋滄煇涓暟鎹垪閲屽寘鍚殑鍑�鏄簺璇稿 鈥�0/1鈥� 鎴� 鈥淵/N鈥� 绛夊�硷紝灏辨病鏈夊繀瑕佷负瀹冨垱寤轰竴涓储寮曘��
绱㈠紩绫诲埆
1锛庢櫘閫氱储寮�
鏅�氱储寮曪紙鐢卞叧閿瓧 KEY 鎴� INDEX 瀹氫箟鐨勭储寮曪級鐨勫敮涓�浠诲姟鏄姞蹇鏁版嵁鐨勮闂�熷害銆傚洜姝わ紝搴旇鍙负閭d簺鏈�缁忓父鍑虹幇鍦ㄦ煡璇㈡潯浠讹紙WHERE column =锛夋垨鎺掑簭鏉′欢锛圤RDER BY column锛変腑鐨勬暟鎹垪鍒涘缓绱㈠紩銆傚彧瑕佹湁鍙兘锛屽氨搴旇閫夋嫨涓�涓暟鎹渶鏁撮綈銆佹渶绱у噾鐨勬暟鎹垪锛堝涓�涓暣鏁扮被鍨嬬殑鏁版嵁鍒楋級鏉ュ垱寤虹储寮曘��
2锛庡敮涓�绱㈠紩
鏅�氱储寮曞厑璁歌绱㈠紩鐨勬暟鎹垪鍖呭惈閲嶅鐨勫�笺�傛瘮濡傝锛屽洜涓轰汉鏈夊彲鑳藉悓鍚嶏紝鎵�浠ュ悓涓�涓鍚嶅湪鍚屼竴涓�滃憳宸ヤ釜浜鸿祫鏂欌�濇暟鎹〃閲屽彲鑳藉嚭鐜颁袱娆℃垨鏇村娆°��
濡傛灉鑳界‘瀹氭煇涓暟鎹垪灏嗗彧鍖呭惈褰兼鍚勪笉鐩稿悓鐨勫�硷紝鍦ㄤ负杩欎釜鏁版嵁鍒楀垱寤虹储寮曠殑鏃跺�欏氨搴旇鐢ㄥ叧閿瓧UNIQUE 鎶婂畠瀹氫箟涓轰竴涓敮涓�绱㈠紩銆傝繖涔堝仛鐨勫ソ澶勶細涓�鏄畝鍖栦簡 MySQL 瀵硅繖涓储寮曠殑绠$悊宸ヤ綔锛岃繖涓储寮曚篃鍥犳鑰屽彉寰楁洿鏈夋晥鐜囷紱浜屾槸 MySQL 浼氬湪鏈夋柊璁板綍鎻掑叆鏁版嵁琛ㄦ椂锛岃嚜鍔ㄦ鏌ユ柊璁板綍鐨勮繖涓瓧娈电殑鍊兼槸鍚﹀凡缁忓湪鏌愪釜璁板綍鐨勮繖涓瓧娈甸噷鍑虹幇杩囦簡锛涘鏋滄槸锛孧ySQL 灏嗘嫆缁濇彃鍏ラ偅鏉℃柊璁板綍銆備篃灏辨槸璇达紝鍞竴绱㈠紩鍙互淇濊瘉鏁版嵁璁板綍鐨勫敮涓�鎬с�備簨瀹炰笂锛屽湪璁稿鍦哄悎锛屼汉浠垱寤哄敮涓�绱㈠紩鐨勭洰鐨勫線寰�涓嶆槸涓轰簡鎻愰珮璁块棶閫熷害锛岃�屽彧鏄负浜嗛伩鍏嶆暟鎹嚭鐜伴噸澶嶃��
3锛庝富绱㈠紩
鍦ㄥ墠闈㈠凡缁忓弽澶嶅娆″己璋冭繃锛氬繀椤讳负涓婚敭瀛楁鍒涘缓涓�涓储寮曪紝杩欎釜绱㈠紩灏辨槸鎵�璋撶殑鈥滀富绱㈠紩鈥濄�備富绱㈠紩涓庡敮涓�绱㈠紩鐨勫敮涓�鍖哄埆鏄細鍓嶈�呭湪瀹氫箟鏃朵娇鐢ㄧ殑鍏抽敭瀛楁槸 PRIMARY 鑰屼笉鏄� UNIQUE銆�
4锛庡閿储寮�
濡傛灉涓烘煇涓閿瓧娈靛畾涔変簡涓�涓閿害鏉熸潯浠讹紝MySQL 灏变細瀹氫箟涓�涓唴閮ㄧ储寮曟潵甯姪鑷繁浠ユ渶鏈夋晥鐜囩殑鏂瑰紡鍘荤鐞嗗拰浣跨敤澶栭敭绾︽潫鏉′欢銆�
5锛庡鍚堢储寮�
绱㈠紩鍙互瑕嗙洊澶氫釜鏁版嵁鍒楋紝濡傚儚 INDEX (columnA, columnB) 绱㈠紩銆傝繖绉嶇储寮曠殑鐗圭偣鏄� MySQL 鍙互鏈夐�夋嫨鍦颁娇鐢ㄤ竴涓繖鏍风殑绱㈠紩銆傚鏋滄煡璇㈡搷浣滃彧闇�瑕佺敤鍒� columnA 鏁版嵁鍒椾笂鐨勪竴涓储寮曪紝灏卞彲浠ヤ娇鐢ㄥ鍚堢储寮� INDEX(columnA, columnB)銆備笉杩囷紝杩欑鐢ㄦ硶浠呴�傜敤浜庡湪澶嶅悎绱㈠紩涓帓鍒楀湪鍓嶇殑鏁版嵁鍒楃粍鍚堛�傛瘮濡傝锛孖NDEX (A锛孊锛孋) 鍙互褰撳仛 A 鎴� (A,B) 鐨勭储寮曟潵浣跨敤锛屼絾涓嶈兘褰撳仛 B銆丆 鎴� (B,C) 鐨勭储寮曟潵浣跨敤銆�
绱㈠紩闀垮害
鍦ㄤ负 CHAR 鍜� VARCHAR 绫诲瀷鐨勬暟鎹垪瀹氫箟绱㈠紩鏃讹紝鍙互鎶婄储寮曠殑闀垮害闄愬埗涓轰竴涓粰瀹氱殑瀛楃涓暟锛堣繖涓暟瀛楀繀椤诲皬浜庤繖涓瓧娈垫墍鍏佽鐨勬渶澶у瓧绗︿釜鏁帮級銆傝繖涔堝仛鐨勫ソ澶勬槸鍙互鐢熸垚涓�涓昂瀵告瘮杈冨皬銆佹绱㈤�熷害鍗存瘮杈冨揩鐨勭储寮曟枃浠躲�傚湪缁濆ぇ澶氭暟搴旂敤閲岋紝鏁版嵁搴撲腑鐨勫瓧绗︿覆鏁版嵁澶ч兘浠ュ悇绉嶅悇鏍风殑鍚嶅瓧涓轰富锛屾妸绱㈠紩鐨勯暱搴﹁缃负10~15 涓瓧绗﹀凡缁忚冻浠ユ妸鎼滅储鑼冨洿缂╁皬鍒板緢灏戠殑鍑犳潯鏁版嵁璁板綍浜嗐�傚湪涓� BLOB 鍜� TEXT 绫诲瀷鐨勬暟鎹垪鍒涘缓绱㈠紩鏃讹紝蹇呴』瀵圭储寮曠殑闀垮害鍋氬嚭闄愬埗锛汳ySQL 鎵�鍏佽鐨勬渶澶х储寮曞叏鏂囩储寮曟枃鏈瓧娈典笂鐨勬櫘閫氱储寮曞彧鑳藉姞蹇鍑虹幇鍦ㄥ瓧娈靛唴瀹规渶鍓嶉潰鐨勫瓧绗︿覆锛堜篃灏辨槸瀛楁鍐呭寮�澶寸殑瀛楃锛夎繘琛屾绱㈡搷浣溿�傚鏋滃瓧娈甸噷瀛樻斁鐨勬槸鐢卞嚑涓�佺敋鑷虫槸澶氫釜鍗曡瘝鏋勬垚鐨勮緝澶ф鏂囧瓧锛屾櫘閫氱储寮曞氨娌′粈涔堜綔鐢ㄤ簡銆傝繖绉嶆绱㈠線寰�浠ョ殑褰㈠紡鍑虹幇锛岃繖瀵� MySQL 鏉ヨ寰堝鏉傦紝濡傛灉闇�瑕佸鐞嗙殑鏁版嵁閲忓緢澶э紝鍝嶅簲鏃堕棿灏变細寰堥暱銆�
杩欑被鍦哄悎姝f槸鍏ㄦ枃绱㈠紩锛坒ull-textindex锛夊彲浠ュぇ鏄捐韩鎵嬬殑鍦版柟銆傚湪鐢熸垚杩欑绫诲瀷鐨勭储寮曟椂锛孧ySQL 灏嗘妸鍦ㄦ枃鏈腑鍑虹幇鐨勬墍鏈夊崟璇嶅垱寤轰负涓�浠芥竻鍗曪紝鏌ヨ鎿嶄綔灏嗘牴鎹繖浠芥竻鍗曞幓妫�绱㈡湁鍏崇殑鏁版嵁璁板綍銆傚叏鏂囩储寮曞嵆鍙互闅忔暟鎹〃涓�鍚屽垱寤猴紝涔熷彲浠ョ瓑鏃ュ悗鏈夊繀瑕佹椂鍐嶄娇鐢ㄤ笅闈㈣繖鏉″懡浠ゆ坊鍔狅細
ALTER TABLE tablename ADD FULLTEXT锛坈olumn1锛宑olumn2锛夋湁浜嗗叏鏂囩储寮曪紝灏卞彲浠ョ敤 SELECT 鏌ヨ鍛戒护鍘绘绱㈤偅浜涘寘鍚潃涓�涓垨澶氫釜缁欏畾鍗曡瘝鐨勬暟鎹褰曚簡銆備笅闈㈡槸杩欑被鏌ヨ鍛戒护鐨勫熀鏈娉曪細
SELECT * FROM tablename
WHERE MATCH (column1,column2) AGAINST('word1','word2','word3')
涓婇潰杩欐潯鍛戒护灏嗘妸 column1 鍜� column2 瀛楁閲屾湁 word1銆亀ord2 鍜� word3 鐨勬暟鎹褰曞叏閮ㄦ煡璇㈠嚭鏉ャ��
娉ㄨВ锛欼nnoDB 鏁版嵁琛ㄤ笉鏀寔鍏ㄦ枃绱㈠紩銆�
鏌ヨ鍜岀储寮�
鍙湁褰撴暟鎹簱閲屽凡缁忔湁浜嗚冻澶熷鐨勬祴璇曟暟鎹椂锛屽畠鐨勬�ц兘娴嬭瘯缁撴灉鎵嶆湁瀹為檯鍙傝�冧环鍊笺�傚鏋滃湪娴嬭瘯鏁版嵁搴撻噷鍙湁鍑犵櫨鏉℃暟鎹褰曪紝瀹冧滑寰�寰�鍦ㄦ墽琛屽畬绗竴鏉℃煡璇㈠懡浠や箣鍚庡氨琚叏閮ㄥ姞杞藉埌鍐呭瓨閲岋紝杩欏皢浣垮悗缁殑鏌ヨ鍛戒护閮芥墽琛屽緱闈炲父蹇�--涓嶇鏈夋病鏈変娇鐢ㄧ储寮曘�傚彧鏈夊綋鏁版嵁搴撻噷鐨勮褰曡秴杩囦簡 1000 鏉°�佹暟鎹�婚噺涔熻秴杩囦簡 MySQL 鏈嶅姟鍣ㄤ笂鐨勫唴瀛樻�婚噺鏃讹紝鏁版嵁搴撶殑鎬ц兘娴嬭瘯缁撴灉鎵嶆湁鎰忎箟銆�
鍦ㄤ笉纭畾搴旇鍦ㄥ摢浜涙暟鎹垪涓婂垱寤虹储寮曠殑鏃跺�欙紝浜轰滑浠� EXPLAIN SELECT 鍛戒护閭i噷寰�寰�鍙互鑾峰緱涓�浜涘府鍔┿�傝繖鍏跺疄鍙槸绠�鍗曞湴缁欎竴鏉℃櫘閫氱殑 SELECT 鍛戒护鍔犱竴涓� EXPLAIN 鍏抽敭瀛椾綔涓哄墠缂�鑰屽凡銆傛湁浜嗚繖涓叧閿瓧锛孧ySQL 灏嗕笉鏄幓鎵ц閭f潯 SELECT 鍛戒护锛岃�屾槸鍘诲瀹冭繘琛屽垎鏋愩�侻ySQL 灏嗕互琛ㄦ牸鐨勫舰寮忔妸鏌ヨ鐨勬墽琛岃繃绋嬪拰鐢ㄥ埌鐨勭储寮曠瓑淇℃伅鍒楀嚭鏉ャ��
鍦� EXPLAIN 鍛戒护鐨勮緭鍑虹粨鏋滈噷锛岀1鍒楁槸浠庢暟鎹簱璇诲彇鐨勬暟鎹〃鐨勫悕瀛楋紝瀹冧滑鎸夎璇诲彇鐨勫厛鍚庨『搴忔帓鍒椼�倀ype鍒楁寚瀹氫簡鏈暟鎹〃涓庡叾瀹冩暟鎹〃涔嬮棿鐨勫叧鑱斿叧绯伙紙JOIN锛夈�傚湪鍚勭绫诲瀷鐨勫叧鑱斿叧绯诲綋涓紝鏁堢巼鏈�楂樼殑鏄� system锛岀劧鍚庝緷娆℃槸 const銆乪q_ref銆乺ef銆乺ange銆乮ndex 鍜� All锛圓ll 鐨勬剰鎬濇槸锛氬搴斾簬涓婁竴绾ф暟鎹〃閲岀殑姣忎竴鏉¤褰曪紝杩欎釜鏁版嵁琛ㄩ噷鐨勬墍鏈夎褰曢兘蹇呴』琚鍙栦竴閬嶁�斺�旇繖绉嶆儏鍐靛線寰�鍙互鐢ㄤ竴绱㈠紩鏉ラ伩鍏嶏級銆�
possible_keys 鏁版嵁鍒楃粰鍑轰簡 MySQL 鍦ㄦ悳绱㈡暟鎹褰曟椂鍙�夌敤鐨勫悇涓储寮曘�俴ey 鏁版嵁鍒楁槸 MySQL 瀹為檯閫夌敤鐨勭储寮曪紝杩欎釜绱㈠紩鎸夊瓧鑺傝绠楃殑闀垮害鍦� key_len 鏁版嵁鍒楅噷缁欏嚭銆傛瘮濡傝锛屽浜庝竴涓� INTEGER 鏁版嵁鍒楃殑绱㈠紩锛岃繖涓瓧鑺傞暱搴﹀皢鏄�4銆傚鏋滅敤鍒颁簡澶嶅悎绱㈠紩锛屽湪 key_len 鏁版嵁鍒楅噷杩樺彲浠ョ湅鍒� MySQL 鍏蜂綋浣跨敤浜嗗畠鐨勫摢浜涢儴鍒嗐�備綔涓轰竴鑸寰嬶紝key_len 鏁版嵁鍒楅噷鐨勫�艰秺灏忚秺濂姐��
ref 鏁版嵁鍒楃粰鍑轰簡鍏宠仈鍏崇郴涓彟涓�涓暟鎹〃閲岀殑鏁版嵁鍒楃殑鍚嶅瓧銆俽ow 鏁版嵁鍒楁槸 MySQL 鍦ㄦ墽琛岃繖涓煡璇㈡椂棰勮浼氫粠杩欎釜鏁版嵁琛ㄩ噷璇诲嚭鐨勬暟鎹鐨勪釜鏁般�俽ow 鏁版嵁鍒楅噷鐨勬墍鏈夋暟瀛楃殑涔樼Н鍙互澶ц嚧浜嗚В杩欎釜鏌ヨ闇�瑕佸鐞嗗灏戠粍鍚堛��
鏈�鍚庯紝extra 鏁版嵁鍒楁彁渚涗簡涓� JOIN 鎿嶄綔鏈夊叧鐨勬洿澶氫俊鎭紝姣斿璇达紝濡傛灉 MySQL 鍦ㄦ墽琛岃繖涓煡璇㈡椂蹇呴』鍒涘缓涓�涓复鏃舵暟鎹〃锛屽氨浼氬湪 extra 鍒楃湅鍒� usingtemporary 瀛楁牱銆�
瀹夎鏁欑▼缂栬緫
鎵撳紑涓嬭浇鐨刴ysql瀹夎鏂囦欢mysql-5.0.27-win32.zip锛屽弻鍑昏В鍘嬬缉锛岃繍琛屸�渟etup.exe鈥�
mysql瀹夎鍚戝鍚姩锛屾寜鈥淣ext鈥濈户缁�,
閫夋嫨瀹夎绫诲瀷锛屾湁鈥淭ypical锛堥粯璁わ級鈥濄�佲�淐omplete锛堝畬鍏級鈥濄�佲�淐ustom锛堢敤鎴疯嚜瀹氫箟锛夆�濅笁涓�夐」锛屾垜浠�夋嫨鈥淐ustom鈥濓紝鏈夋洿澶氱殑閫夐」锛屼篃鏂逛究鐔熸倝瀹夎杩囩▼:
鍦ㄢ�淒eveloper Components锛堝紑鍙戣�呴儴鍒嗭級鈥濅笂宸﹂敭鍗曞嚮锛岄�夋嫨鈥淭his feature, and all subfeatures, will be installed on local hard drive.鈥濓紝鍗斥�滄閮ㄥ垎锛屽強涓嬪睘瀛愰儴鍒嗗唴瀹癸紝鍏ㄩ儴瀹夎鍦ㄦ湰鍦扮‖鐩樹笂鈥濄�傚湪涓婇潰鐨勨�淢ySQL Server锛坢ysql鏈嶅姟鍣級鈥濄�佲�淐lient Programs锛坢ysql瀹㈡埛绔▼搴忥級鈥濄�佲�淒ocumentation锛堟枃妗o級鈥濅篃濡傛鎿嶄綔锛屼互淇濊瘉瀹夎鎵�鏈夋枃浠躲�傜偣閫夆�淐hange...鈥濓紝鎵� 鍔ㄦ寚瀹氬畨瑁呯洰褰曘��
濉笂瀹夎鐩綍锛屾垜鐨勬槸鈥淔:\Server\MySQL\MySQL Server 5.0鈥濓紝涔熷缓璁笉瑕佹斁鍦ㄤ笌鎿嶄綔绯荤粺鍚屼竴鍒嗗尯锛岃繖鏍峰彲浠ラ槻姝㈢郴缁熷浠借繕鍘熺殑鏃跺�欙紝鏁版嵁琚竻绌恒�傛寜鈥淥K鈥濈户缁��
杩斿洖鍒氭墠鐨勭晫闈紝鎸夆�淣ext鈥濈户缁�
纭涓�涓嬪厛鍓嶇殑璁剧疆锛屽鏋滄湁璇紝鎸夆�淏ack鈥濊繑鍥為噸鍋氥�傛寜鈥淚nstall鈥濆紑濮嬪畨瑁呫��
姝e湪瀹夎涓紝璇风◢鍊欙紝鐩村埌鍑虹幇涓嬮潰鐨勭晫闈�
杩欓噷鏄闂綘鏄惁瑕佹敞鍐屼竴涓处鍙凤紝鎴栨槸浣跨敤宸叉湁鐨勮处鍙风洿鎺ョ櫥闄嗭紝涓�鑸笉闇�瑕佷簡锛岀偣閫夆�淪kip Sign-Up鈥濓紝鎸夆�淣ext鈥濈暐杩囨姝ラ銆�
杞欢瀹夎瀹屾垚鍚庯紝鍑虹幇涓婇潰鐨勭晫闈紝杩欓噷鏈変竴涓緢濂界殑鍔熻兘锛宮ysql閰嶇疆鍚戝锛屼笉鐢ㄥ悜 浠ュ墠涓�鏍凤紝鑷繁鎵嬪姩涔变竷鍏碂鐨勯厤缃甿y.ini浜嗭紝灏� 鈥淐onfigure the Mysql Server now鈥濆墠闈㈢殑鍕炬墦涓婏紝鐐光�淔inish鈥濈粨鏉熻蒋浠剁殑瀹夎骞跺惎鍔╩ysql閰嶇疆鍚戝銆�
mysql閰嶇疆鍚戝鍚姩鐣岄潰锛屾寜鈥淣ext鈥濈户缁�
閫夋嫨閰嶇疆鏂瑰紡锛屸�淒etailed Configuration锛堟墜鍔ㄧ簿纭厤缃級鈥濄�佲�淪tandard Configuration锛堟爣鍑嗛厤缃級鈥濓紝鎴戜滑閫夋嫨鈥淒etailed Configuration鈥濓紝鏂逛究鐔熸倝閰嶇疆杩囩▼銆�
閫夋嫨鏈嶅姟鍣ㄧ被鍨嬶紝鈥淒eveloper Machine锛堝紑鍙戞祴璇曠被锛宮ysql鍗犵敤寰堝皯璧勬簮锛夆�濄�佲�淪erver Machine锛堟湇鍔″櫒绫诲瀷锛宮ysql鍗犵敤杈冨璧勬簮锛夆�濄�佲�淒edicatedMySQL Server Machine锛堜笓闂ㄧ殑鏁版嵁搴撴湇鍔″櫒锛宮ysql鍗犵敤鎵�鏈夊彲鐢ㄨ祫婧愶級鈥濓紝澶у鏍规嵁鑷繁鐨勭被鍨嬮�夋嫨浜嗭紝涓�鑸�夆�淪erver Machine鈥濓紝涓嶄細澶皯锛屼篃涓嶄細鍗犳弧銆�
閫夋嫨mysql鏁版嵁搴撶殑澶ц嚧鐢ㄩ�旓紝鈥淢ultifunctional Database锛堥�氱敤澶氬姛鑳藉瀷锛屽ソ锛夆�濄�佲�淭ransactional Database Only锛堟湇鍔″櫒绫诲瀷锛屼笓娉ㄤ簬浜嬪姟澶勭悊锛屼竴鑸級鈥濄�佲�淣on-Transactional Database Only锛堥潪浜嬪姟澶勭悊鍨嬶紝杈冪畝鍗曪紝涓昏鍋氫竴浜涚洃鎺с�佽鏁扮敤锛屽MyISAM鏁版嵁绫诲瀷鐨勬敮鎸佷粎闄愪簬non-transactional锛夛紝闅忚嚜宸辩殑鐢ㄩ�旇�岄�� 鎷╀簡锛屾垜杩欓噷閫夋嫨鈥淭ransactional Database Only鈥濓紝鎸夆�淣ext鈥濈户缁��
瀵笽nnoDB Tablespace杩涜閰嶇疆锛屽氨鏄负InnoDB 鏁版嵁搴撴枃浠堕�夋嫨涓�涓瓨鍌ㄧ┖闂达紝濡傛灉淇敼浜嗭紝瑕佽浣忎綅缃紝閲嶈鐨勬椂鍊欒閫夋嫨涓�鏍风殑鍦版柟锛屽惁鍒欏彲鑳戒細閫犳垚鏁版嵁搴撴崯鍧忥紝褰撶劧锛屽鏁版嵁搴撳仛涓浠藉氨娌¢棶棰樹簡锛岃繖閲� 涓嶈杩般�傛垜杩欓噷娌℃湁淇敼锛屼娇鐢ㄧ敤榛樿浣嶇疆锛岀洿鎺ユ寜鈥淣ext鈥濈户缁�
閫夋嫨鎮ㄧ殑缃戠珯鐨勪竴鑸琺ysql璁块棶閲忥紝鍚屾椂杩炴帴鐨勬暟鐩紝鈥淒ecision Support(DSS)/OLAP锛�20涓乏鍙筹級鈥濄�佲�淥nline Transaction Processing(OLTP)锛�500涓乏鍙筹級鈥濄�佲�淢anual Setting锛堟墜鍔ㄨ缃紝鑷繁杈撲竴涓暟锛夆�濓紝鎴戣繖閲岄�夆�淥nline Transaction Processing(OLTP)鈥濓紝鑷繁鐨勬湇鍔″櫒锛屽簲璇ュ鐢ㄤ簡锛屾寜鈥淣ext鈥濈户缁�
鏄惁鍚敤TCP/IP杩炴帴锛岃瀹氱鍙o紝濡傛灉涓嶅惎鐢紝灏卞彧鑳藉湪鑷繁鐨勬満鍣ㄤ笂璁块棶mysql鏁� 鎹簱浜嗭紝鎴戣繖閲屽惎鐢紝鎶婂墠闈㈢殑鍕炬墦涓婏紝Port Number锛�3306锛屽湪杩欎釜椤甸潰涓婏紝鎮ㄨ繕鍙互閫夋嫨鈥滃惎鐢ㄦ爣鍑嗘ā寮忊�濓紙Enable Strict Mode锛夛紝杩欐牱MySQL灏变笉浼氬厑璁哥粏灏忕殑璇硶閿欒銆傚鏋滄偍杩樻槸涓柊鎵嬶紝鎴戝缓璁偍鍙栨秷鏍囧噯妯″紡浠ュ噺灏戦夯鐑︺�備絾鐔熸倝MySQL浠ュ悗锛屽敖閲忎娇鐢ㄦ爣鍑嗘ā寮忥紝鍥� 涓哄畠鍙互闄嶄綆鏈夊鏁版嵁杩涘叆鏁版嵁搴撶殑鍙兘鎬с�傛寜鈥淣ext鈥濈户缁�
瑗挎枃缂栫爜锛岀浜屼釜鏄瀛楄妭鐨勯�氱敤utf8缂栫爜锛岄兘涓嶆槸鎴戜滑閫氱敤鐨勭紪鐮侊紝杩欓噷閫夋嫨绗笁涓紝鐒� 鍚庡湪Character Set閭i噷閫夋嫨鎴栧~鍏モ�済bk鈥濓紝褰撶劧涔熷彲浠ョ敤鈥済b2312鈥濓紝鍖哄埆灏辨槸gbk鐨勫瓧搴撳閲忓ぇ锛屽寘鎷簡gb2312鐨勬墍鏈夋眽瀛楋紝骞朵笖鍔犱笂浜嗙箒浣撳瓧銆佸拰鍏跺畠 涔变竷鍏碂鐨勫瓧鈥斺�斾娇鐢╩ysql鐨勬椂鍊欙紝鍦ㄦ墽琛屾暟鎹搷浣滃懡浠や箣鍓嶈繍琛屼竴娆♀�淪ET NAMES GBK;鈥濓紙杩愯涓�娆″氨琛屼簡锛孏BK鍙互鏇挎崲涓哄叾瀹冨�硷紝瑙嗚繖閲岀殑璁剧疆鑰屽畾锛夛紝灏卞彲浠ユ甯哥殑浣跨敤姹夊瓧锛堟垨鍏跺畠鏂囧瓧锛変簡锛屽惁鍒欎笉鑳芥甯告樉绀烘眽瀛椼�傛寜 鈥淣ext鈥濈户缁�俒5]
閫夋嫨鏄惁灏唌ysql瀹夎涓簑indows鏈嶅姟锛岃繕鍙互鎸囧畾Service Name锛堟湇鍔℃爣璇嗗悕绉帮級锛屾槸鍚﹀皢mysql鐨刡in鐩綍鍔犲叆鍒癢indows PATH锛堝姞鍏ュ悗锛屽氨鍙互鐩存帴浣跨敤bin涓嬬殑鏂囦欢锛岃�屼笉鐢ㄦ寚鍑虹洰褰曞悕锛屾瘮濡傝繛鎺ワ紝鈥渕ysql.exe -uusername -ppassword;鈥濆氨鍙互浜嗭紝涓嶇敤鎸囧嚭mysql.exe鐨勫畬鏁村湴鍧�锛屽緢鏂逛究锛夛紝鎴戣繖閲屽叏閮ㄦ墦涓婁簡鍕撅紝Service Name涓嶅彉銆傛寜鈥淣ext鈥濈户缁��
杩欎竴姝ヨ闂槸鍚﹁淇敼榛樿root鐢ㄦ埛锛堣秴绾х鐞嗭級鐨勫瘑鐮侊紙榛樿涓虹┖锛夛紝鈥淣ew root password鈥濆鏋滆淇敼锛屽氨鍦ㄦ濉叆鏂板瘑鐮侊紙濡傛灉鏄噸瑁咃紝骞朵笖涔嬪墠宸茬粡璁剧疆浜嗗瘑鐮侊紝鍦ㄨ繖閲屾洿鏀瑰瘑鐮佸彲鑳戒細鍑洪敊锛岃鐣欑┖锛屽苟灏嗏�淢odify Security Settings鈥濆墠闈㈢殑鍕惧幓鎺夛紝瀹夎閰嶇疆瀹屾垚鍚庡彟琛屼慨鏀瑰瘑鐮侊級锛屸�淐onfirm锛堝啀杈撲竴閬嶏級鈥濆唴鍐嶅~涓�娆★紝闃叉杈撻敊銆� 鈥淓nable root access from remote machines锛堟槸鍚﹀厑璁竢oot鐢ㄦ埛鍦ㄥ叾瀹冪殑鏈哄櫒涓婄櫥闄嗭紝濡傛灉瑕佸畨鍏紝灏变笉瑕佸嬀涓婏紝濡傛灉瑕佹柟渚匡紝灏卞嬀涓婂畠锛夆�濄�傛渶鍚庘�淐reate An Anonymous Account锛堟柊寤轰竴涓尶鍚嶇敤鎴凤紝鍖垮悕鐢ㄦ埛鍙互杩炴帴鏁版嵁搴擄紝涓嶈兘鎿嶄綔鏁版嵁锛屽寘鎷煡璇級鈥濓紝涓�鑸氨涓嶇敤鍕句簡锛岃缃畬姣曪紝鎸夆�淣ext鈥濈户缁��
纭璁剧疆鏃犺锛屽鏋滄湁璇紝鎸夆�淏ack鈥濊繑鍥炴鏌ャ�傛寜鈥淓xecute鈥濅娇璁剧疆鐢熸晥銆�
璁剧疆瀹屾瘯锛屾寜鈥淔inish鈥濈粨鏉焟ysql鐨勫畨瑁呬笌閰嶇疆鈥斺�旇繖閲屾湁涓�涓瘮杈冨父瑙佺殑閿欒锛� 灏辨槸涓嶈兘鈥淪tart service鈥濓紝涓�鑸嚭鐜板湪浠ュ墠鏈夊畨瑁卪ysql鐨勬湇鍔″櫒涓婏紝瑙e喅鐨勫姙娉曪紝鍏堜繚璇佷互鍓嶅畨瑁呯殑mysql鏈嶅姟鍣ㄥ交搴曞嵏杞芥帀浜嗭紱涓嶈鐨勮瘽锛屾鏌ユ槸鍚︽寜涓婇潰涓� 姝ユ墍璇达紝涔嬪墠鐨勫瘑鐮佹槸鍚︽湁淇敼锛岀収涓婇潰鐨勬搷浣滐紱濡傛灉渚濈劧涓嶈锛屽皢mysql瀹夎鐩綍涓嬬殑data鏂囦欢澶瑰浠斤紝鐒跺悗鍒犻櫎锛屽湪瀹夎瀹屾垚鍚庯紝灏嗗畨瑁呯敓鎴愮殑 data鏂囦欢澶瑰垹闄わ紝澶囦唤鐨刣ata鏂囦欢澶圭Щ鍥炴潵锛屽啀閲嶅惎mysql鏈嶅姟灏卞彲浠ヤ簡锛岃繖绉嶆儏鍐典笅锛屽彲鑳介渶瑕佸皢鏁版嵁搴撴鏌ヤ竴涓嬶紝鐒跺悗淇涓�娆★紝闃叉鏁版嵁鍑洪敊銆�
瀹夎闂缂栬緫
1锛庡鏋滄槸鐢� MySQL + Apache锛屼娇鐢ㄧ殑鍙堟槸 FreeBSD 缃戠粶鎿嶄綔绯荤粺鐨勮瘽锛屽畨瑁呮椂鍊欎綘搴旀寜娉ㄦ剰鍒癋reeBSD鐨勭増鏈棶棰橈紝鍦� FreeBSD 鐨� 3.0 浠ヤ笅鐗堟湰鏉ヨ锛孧ySQL Source 鍐呭惈鐨� MIT-pthread 杩愯鏄甯哥殑锛屼絾鍦ㄨ繖鐗堟湰浠ヤ笂锛屼綘蹇呴』浣跨敤 native threads锛屼篃灏辨槸鍔犲叆涓�涓� with-named-thread-libs=-lc_r 鐨勯�夐」銆�
2锛庡鏋滃湪 COMPILE 杩囩▼涓嚭浜嗛棶棰橈紝璇峰厛妫�鏌ヤ綘鐨� gcc鐗堟湰鏄惁鍦� 2.81 鐗堟湰浠ヤ笂锛実make 鐗堟湰鏄惁鍦�3.75浠ヤ笂銆�
3锛庡鏋滀笉鏄増鏈殑闂锛岄偅鍙兘鏄綘鐨勫唴瀛樹笉瓒筹紝璇蜂娇鐢� ./configure--with-low-memory 鏉ュ姞鍏ャ��
4锛庡鏋滆閲嶆柊鍋氫綘鐨� configure锛岄偅涔堜綘鍙互閿叆 rm config.cache 鍜� make clean 鏉ユ竻闄よ褰曘��
5锛庢妸 MySQL 瀹夎鍦� /usr/local 鐩綍涓嬶紝杩欐槸缂虹渷鍊硷紝鎮ㄤ篃鍙互鎸夌収浣犵殑闇�瑕佽瀹氫綘鎵�瀹夎鐨勭洰褰曘��
MySQL鏈嶅姟鏃犳硶鍚姩
1銆侀鍏堬紝鏌ョ湅MySQL鐨勬湇鍔℃槸鍚﹀瓨鍦ㄣ�傚鏋滀笉瀛樺湪闇�瑕佸厛瀹夎鏈嶅姟銆傚畨瑁呮湇鍔$殑鏂规硶鏄繘鍏ySQL Server鐨勫畨瑁呯洰褰曪紝鎵惧埌bin鐩綍锛岀劧鍚庢壘鍒版枃浠秏ysqld.exe锛屼娇鐢ㄥ懡浠よ杩愯 mysqld --install MySQL57 瀹夎鏈嶅姟(濡傛灉涓嶆垚鍔熷皾璇曚娇鐢ㄧ鐞嗗憳鏂瑰紡杩愯,MySQL57鏄湇鍔$殑鍚嶅瓧锛岄粯璁ゆ槸MySQL)銆�
MySQL鏈嶅姟鏃犳硶鍚姩
MySQL鏈嶅姟鏃犳硶鍚姩
2銆佸鏋滀笂杩版柟娉曞畨瑁呮湇鍔″け璐ワ紝鍒欏彲閲囩敤涓嬭堪鏂规硶瀹夎(鎴愬姛鍒欒烦杩囨姝�)銆傛悳绱㈢▼搴忊�渞egedit.exe鈥濓紝鍗虫敞鍐岃〃缂栬緫鍣紝鎵撳紑鍚庢壘鍒� 鈥滆绠楁満鈥濃�斺��"HKEY_LOCAL_MACHINE"鈥斺�斺�淪YSTEM鈥濃�斺�斺�淐urrentControlSet鈥濃�斺�斺�淪ervices鈥�,鐒跺悗鍦ㄨ鐩綍涓嬫柊寤洪」MySQL57(鏈嶅姟鐨勫悕瀛�)鍗冲彲鎴愬姛寤虹珛椤圭洰銆�
3銆佹壘鍒版柊寤虹殑椤癸紝鐒跺悗鍙互鐪嬪埌鍏朵腑鏈塈magePath杩欎竴椤癸紝杩欏叾瀹炴槸鍙墽琛屾枃浠剁殑璺緞銆傚洜涓篗ySQL鏈嶅姟鏄渶瑕侀潬mysqld杩欎釜鍛戒护鏉ュ惎鍔ㄧ殑锛屾墍浠ユ鏌ヤ笅ImagePath鐨勮矾寰勬槸鍚︽纭�傝矾寰勯敊璇鑷村惎鍔ㄦ湇鍔℃椂鎶ラ敊鈥斺�滄棤娉曟壘鍒版枃浠垛�濄��
4銆佷慨鏀笽magePath鐨勫唴瀹逛负姝g‘鐨勮矾寰勫�硷紝姝g‘鐨勫�兼槸"D:\MySQL\MySQL Server 5.7\bin\mysqld" --defaults-file="D:\MySQL\MySQL Server 5.7\my.ini" MySQL 鏄繖绉嶅舰寮忕殑锛屽鐓т竴涓嬶紝濡傛灉璺緞涓嶅锛屼慨鏀硅繃鏉ャ��
5銆侀噸鍚绠楁満锛屽啀娆″惎鍔ㄦ湇鍔★紝骞跺彲浠ユ垚鍔熻繍琛孧ySQL鏈嶅姟銆俒6]
鎶ラ敊瑙e喅缂栬緫
1锛嶴tarting MySQL.Manager of pid-file quit without updating fi[澶辫触]
鍏充簬杩欎釜閿欒鍘熷洜鏈夊緢澶氾紝鏈�澶х殑鍙兘鏄病鏈夊垱寤烘祴璇曟暟鎹簱锛屽彲浠ョ敤/usr/local/mysql/scripts/mysql_install_db 鈥搖ser=mysql鍛戒护杩涜鍒涘缓锛涘彟澶栦竴涓師鍥犲彲鑳芥槸鏉冮檺璁剧疆闂锛岄渶瑕佽祴浜坢ysql鐨刣ata鏉冮檺锛屽彲浠ョ敤chmod -R 鍛戒护銆�
2锛嶧ATAL ERROR: Could not find /home/mysql/bin/my_print_defaults If you are using a binary release,you must run this script from
within the directory the archive extracted into. If you compiled
MySQL yourself you must run 鈥榤ake install鈥� first.
杩欎釜閿欒锛屾槸娌℃湁鎸囨槑mysql鐨刣ata璺緞瀵艰嚧鐨勶紝鍙互寰堢畝鍗曠殑杩涜瑙e喅锛�
vim /etc/my.cnf
鍦╗mysqld] 鍚庨潰鍔犱笂璺緞锛�
basedir = /usr/local/mysql
datadir =/opt/data锛�
3锛�-bash: mysql: command not found
鐢╩ysql鍛戒护杩涜鐧婚檰mysql鎶ラ敊锛屽師鍥犳槸娌℃湁璁剧疆鐜鍙橀噺锛岄渶瑕佽缃紝鎴栬�呰繘鍏ュ埌bin鐩綍杩涜鐧婚檰cd /usr/local/mysql/bin
mysql -u root
4锛嶦RROR 1130: Host 鈥�192.168.1.3鈥� is not allowed to connect to this MySQL server
鐢╩ysql杩滅▼宸ュ叿閾炬帴鏁版嵁搴撴姤閿欙紝杩欎釜閿欒鍘熷洜鏄病鏈夊紑鏀捐繙绋嬮摼鎺ュ姛鑳斤紝鍙互鍦╩ysql閲岄潰杈撳叆濡備笅鍛戒护杩涜瑙e喅锛欸RANT ALL PRIVILEGES ON *.* TO 鈥檙oot鈥楡鈥�%' IDENTIFIED BY 鈥檖assword鈥� WITH GRANT OPTION
鍒濆鍩虹缂栬緫
杩炴帴 MySQL
鏍煎紡锛歮ysql -h 涓绘満鍦板潃 -u 鐢ㄦ埛鍚� 锛峱 鐢ㄦ埛瀵嗙爜
1锛庝緥1锛氳繛鎺ュ埌鏈満涓婄殑MYSQL銆�
棣栧厛鍦ㄦ墦寮� DOS 绐楀彛锛岀劧鍚庤繘鍏ョ洰褰� mysqlbin锛屽啀閿叆鍛戒护mysql -uroot -p锛屽洖杞﹀悗鎻愮ず浣犺緭瀵嗙爜锛屽鏋滃垰瀹夎濂組YSQL锛岃秴绾х敤鎴穜oot 鏄病鏈夊瘑鐮佺殑锛屾晠鐩存帴鍥炶溅鍗冲彲杩涘叆鍒� MySQL 涓簡锛孧ySQL 鐨勬彁绀虹鏄細mysql>
2锛庝緥2锛氳繛鎺ュ埌杩滅▼涓绘満涓婄殑MYSQL銆傚亣璁捐繙绋嬩富鏈虹殑IP涓猴細110.110.110.110锛岀敤鎴峰悕涓簉oot,瀵嗙爜涓篴bcd123銆傚垯閿叆浠ヤ笅鍛戒护锛�
mysql -h110.110.110.110 -uroot -pabcd123
锛堟敞锛歶涓巖oot鍙互涓嶇敤鍔犵┖鏍硷紝鍏跺畠涔熶竴鏍凤級
3锛庨��鍑� MySQL 鍛戒护锛歟xit 锛堝洖杞︼級
娉ㄦ剰锛氭兂瑕佹垚鍔熻繛鎺ュ埌杩滅▼涓绘満锛岄渶瑕佸湪杩滅▼涓绘満鎵撳紑MySQL杩滅▼璁块棶鏉冮檺
鏂规硶濡備笅锛�
鍦ㄨ繙绋嬩富鏈轰腑浠ョ鐞嗗憳韬唤杩涘叆
杈撳叆濡備笅鍛戒护
mysql>GRANT ALL PRIVILEGES ON *.* TO 'agui'@%'IDENTIFIEDBY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;
//璧嬩簣浠讳綍涓绘満璁块棶鏁版嵁鐨勬潈闄�
mysql>FLUSH PRIVILEGES
//淇敼鐢熸晥
agui涓烘垜浠娇鐢ㄧ殑鐢ㄦ埛鍚�
瀵嗙爜涓� 123
鍗筹細鍦ㄨ繙绋嬩富鏈轰笂浣滃ソ璁剧疆锛屾垜浠嵆鍙�氳繃mysql -h110.110.110.110 -uagui -p123杩炴帴杩涜繙绋嬩富鏈�
淇敼瀵嗙爜
鏍煎紡锛歮ysqladmin -u鐢ㄦ埛鍚� -p鏃у瘑鐮� password 鏂板瘑鐮�
1锛庝緥1锛氱粰root鍔犱釜瀵嗙爜ab12銆傞鍏堝湪DOS涓嬭繘鍏ョ洰褰昺ysqlbin锛岀劧鍚庨敭鍏ヤ互涓嬪懡浠�
mysqladmin -uroot -password ab12
娉細鍥犱负寮�濮嬫椂root娌℃湁瀵嗙爜锛屾墍浠�-p鏃у瘑鐮佷竴椤瑰氨鍙互鐪佺暐浜嗐��
2锛庝緥2锛氬啀灏唕oot鐨勫瘑鐮佹敼涓篸jg345銆�
mysqladmin -uroot -pab12 password djg345
澧炲姞鏂扮敤鎴�
锛堟敞鎰忥細鍜屼笂闈笉鍚岋紝涓嬮潰鐨勫洜涓烘槸 MySQL 鐜涓殑鍛戒护锛屾墍浠ュ悗闈㈤兘甯︿竴涓垎鍙蜂綔涓哄懡浠ょ粨鏉熺锛�
鏍煎紡锛歡rant select on 鏁版嵁搴�.* to 鐢ㄦ埛鍚岪鐧诲綍涓绘満 identified by 鈥滃瘑鐮佲��
渚�1銆佸鍔犱竴涓敤鎴� test1 瀵嗙爜涓� abc锛岃浠栧彲浠ュ湪浠讳綍涓绘満涓婄櫥褰曪紝骞跺鎵�鏈夋暟鎹簱鏈夋煡璇€�佹彃鍏ャ�佷慨鏀广�佸垹闄ょ殑鏉冮檺銆傞鍏堢敤浠� root 鐢ㄦ埛杩炲叆 MySQL锛岀劧鍚庨敭鍏ヤ互涓嬪懡浠わ細
grant select,insert,update,delete on *.* to test1@鈥�%鈥� Identified by 鈥渁bc鈥�;
浣嗕緥1澧炲姞鐨勭敤鎴锋槸鍗佸垎鍗遍櫓鐨勶紝浣犳兂濡傛煇涓汉鐭ラ亾test1鐨勫瘑鐮侊紝閭d箞浠栧氨鍙互鍦╥nternet涓婄殑浠讳綍涓�鍙扮數鑴戜笂鐧诲綍浣犵殑mysql鏁版嵁搴撳苟瀵逛綘鐨勬暟鎹彲浠ヤ负鎵�娆蹭负浜嗭紝瑙e喅鍔炴硶瑙佷緥2銆�
渚�2銆佸鍔犱竴涓敤鎴� test2 瀵嗙爜涓� abc,璁╀粬鍙彲浠ュ湪 localhost 涓婄櫥褰曪紝骞跺彲浠ュ鏁版嵁搴� mydb 杩涜鏌ヨ銆佹彃鍏ャ�佷慨鏀广�佸垹闄ょ殑鎿嶄綔锛坙ocalhost鎸囨湰鍦颁富鏈猴紝鍗矼YSQL鏁版嵁搴撴墍鍦ㄧ殑閭e彴涓绘満锛夛紝杩欐牱鐢ㄦ埛鍗充娇鐢ㄧ煡閬搕est2鐨勫瘑鐮侊紝浠栦篃鏃犳硶浠巌nternet涓婄洿鎺ヨ闂暟鎹簱锛屽彧鑳介�氳繃MYSQL涓绘満涓婄殑web椤垫潵璁块棶浜嗐��
grant select, insert, update, delete on mydb.* to test2@localhost identified by 鈥渁bc鈥�;
濡傛灉浣犱笉鎯� test2 鏈夊瘑鐮侊紝鍙互鍐嶆墦涓�涓懡浠ゅ皢瀵嗙爜娑堟帀銆�
grant select, insert, update, delete on mydb.* to test2@localhost identified by 鈥溾��;
涓嬮潰鏉ョ湅鐪� MySQL 涓湁鍏虫暟鎹簱鏂归潰鐨勬搷浣溿�傛敞鎰忥細蹇呴』棣栧厛鐧诲綍鍒� MySQL 涓紝浠ヤ笅鎿嶄綔閮芥槸鍦� MySQL 鐨勬彁绀虹涓嬭繘琛岀殑锛岃�屼笖姣忎釜鍛戒护浠ュ垎鍙风粨鏉熴��
鎿嶄綔鎶�宸�
1锛庡鏋滀綘鎵撳懡浠ゆ椂锛屽洖杞﹀悗鍙戠幇蹇樿鍔犲垎鍙凤紝浣犳棤椤婚噸鎵撲竴閬嶅懡浠わ紝鍙鎵撲釜鍒嗗彿鍥炶溅灏卞彲浠ヤ簡銆備篃灏辨槸璇翠綘鍙互鎶婁竴涓畬鏁寸殑鍛戒护鍒嗘垚鍑犺鏉ユ墦锛屽畬鍚庣敤鍒嗗彿浣滅粨鏉熸爣蹇楀氨 OK銆�
2锛庝綘鍙互浣跨敤鍏夋爣涓婁笅閿皟鍑轰互鍓嶇殑鍛戒护銆備絾浠ュ墠鎴戠敤杩囩殑涓�涓� MySQL 鏃х増鏈笉鏀寔銆傛垜鐢ㄧ殑鏄痬ysql-3.23.27-beta-win銆�
鏄剧ず鍛戒护
1锛庢樉绀烘暟鎹簱鍒楄〃銆�
show databases;
鍒氬紑濮嬫椂鎵嶄袱涓暟鎹簱锛歮ysql 鍜� test銆俶ysql 搴撳緢閲嶈瀹冮噷闈㈡湁 MySQL 鐨勭郴缁熶俊鎭紝鎴戜滑鏀瑰瘑鐮佸拰鏂板鐢ㄦ埛锛屽疄闄呬笂灏辨槸鐢ㄨ繖涓簱杩涜鎿嶄綔銆�
2锛庢樉绀哄簱涓殑鏁版嵁琛細
use mysql锛� //鎵撳紑搴擄紝瀛﹁繃 FOXBASE 鐨勪竴瀹氫笉浼氶檶鐢熷惂
show tables;
3锛庢樉绀烘暟鎹〃鐨勭粨鏋勶細
describe 琛ㄥ悕锛�
4锛庡缓搴擄細
create database 搴撳悕锛�
5锛庡缓琛細
use 搴撳悕锛�
create table 琛ㄥ悕 (瀛楁璁惧畾鍒楄〃)锛�
6锛庡垹搴撳拰鍒犺〃锛�
drop database 搴撳悕锛�
drop table 琛ㄥ悕锛�
7锛庡皢琛ㄤ腑璁板綍娓呯┖锛�
delete from 琛ㄥ悕锛�
8锛庢樉绀鸿〃涓殑璁板綍锛�
select * from 琛ㄥ悕锛�
9锛庢樉绀烘渶鍚庝竴涓墽琛岀殑璇彞鎵�浜х敓鐨勯敊璇�佽鍛婂拰閫氱煡锛�
show warnings;
10锛庡彧鏄剧ず鏈�鍚庝竴涓墽琛岃鍙ユ墍浜х敓鐨勯敊璇細
show errors;
瀹炰緥
drop database if exists school; //濡傛灉瀛樺湪SCHOOL鍒欏垹闄�
create database school; //寤虹珛搴揝CHOOL
use school; //鎵撳紑搴揝CHOOL
create table teacher //寤虹珛琛═EACHER
(
id int(3) auto_increment not null primary key,
name char(10) not null,
address varchar(50) default 鈥樻繁鍦�',
year date
); //寤鸿〃缁撴潫
//浠ヤ笅涓烘彃鍏ュ瓧娈�
insert into teacher values('','glchengang',鈥橷X鍏徃鈥橈紝'1976-10-10');
insert into teacher values('','jack',鈥橷X鍏徃鈥橈紝'1975-12-23');
娉細鍦ㄥ缓琛ㄤ腑锛�
1锛庡皢ID璁句负闀垮害涓�3鐨勬暟瀛楀瓧娈碉細int(3)骞惰瀹冩瘡涓褰曡嚜鍔ㄥ姞涓�锛歛uto_increment骞朵笉鑳戒负绌猴細not null鑰屼笖璁╀粬鎴愪负涓诲瓧娈祊rimary key銆�
2锛庡皢NAME璁句负闀垮害涓�10鐨勫瓧绗﹀瓧娈点��
3锛庡皢ADDRESS璁句负闀垮害50鐨勫瓧绗﹀瓧娈碉紝鑰屼笖缂虹渷鍊间负娣卞湷銆倂archar鍜宑har鏈変粈涔堝尯鍒憿锛屽彧鏈夌瓑浠ュ悗鐨勬枃绔犲啀璇翠簡銆�
4锛庡皢YEAR璁句负鏃ユ湡瀛楁銆�
濡傛灉浣犲湪mysql鎻愮ず绗﹂敭鍏ヤ笂闈㈢殑鍛戒护涔熷彲浠ワ紝浣嗕笉鏂逛究璋冭瘯銆備綘鍙互灏嗕互涓婂懡浠ゅ師鏍峰啓鍏ヤ竴涓枃鏈枃浠朵腑鍋囪涓簊chool.sql锛岀劧鍚庡鍒跺埌c:\涓嬶紝骞跺湪DOS鐘舵�佽繘鍏ョ洰褰昞mysql\bin锛岀劧鍚庨敭鍏ヤ互涓嬪懡浠わ細
mysql -uroot -p瀵嗙爜 < c:\school.sql
濡傛灉鎴愬姛锛岀┖鍑轰竴琛屾棤浠讳綍鏄剧ず锛涘鏈夐敊璇紝浼氭湁鎻愮ず銆傦紙浠ヤ笂鍛戒护宸茬粡璋冭瘯锛屼綘鍙灏�//鐨勬敞閲婂幓鎺夊嵆鍙娇鐢級銆�
鏂囨湰杞埌鏁版嵁搴�
1锛庢枃鏈暟鎹簲绗﹀悎鐨勬牸寮忥細瀛楁鏁版嵁涔嬮棿鐢╰ab閿殧寮�锛宯ull鍊肩敤\n鏉ヤ唬鏇�.
渚嬶細
3锛巖ose 娣卞湷浜屼腑 1976-10-10
4锛巑ike 娣卞湷涓�涓� 1975-12-23
2锛庢暟鎹紶鍏ュ懡浠� load data local infile 鈥滄枃浠跺悕鈥� into table 琛ㄥ悕锛�
娉ㄦ剰锛氫綘鏈�濂藉皢鏂囦欢澶嶅埗鍒癨mysql\bin鐩綍涓嬶紝骞朵笖瑕佸厛鐢╱se鍛戒护鎵撳紑琛ㄦ墍鍦ㄧ殑鏁版嵁搴�
鎴栬�呯櫥褰曟暟鎹簱鍓嶅皢璺緞杞Щ锛坈d锛夊埌瑕佸鍏ユ枃鏈墍鍦ㄨ矾寰勩��
澶囦唤鏁版嵁搴�
锛堝懡浠ゅ湪DOS鐨刓mysql\bin鐩綍涓嬫墽琛岋級
mysqldump --opt school>school.bbb
娉ㄩ噴锛氬皢鏁版嵁搴搒chool澶囦唤鍒皊chool.bbb鏂囦欢锛宻chool.bbb鏄竴涓枃鏈枃浠讹紝鏂囦欢鍚嶄换鍙栵紝鎵撳紑鐪嬬湅浣犱細鏈夋柊鍙戠幇銆�
鑷姩澶囦唤 mysql 鏁版嵁搴撶殑鏂规硶
1銆佸厛鏄缓绔嬫壒澶勭悊鏂囦欢锛屽皢浠ヤ笅浠g爜鍙﹀瓨涓�.bat鏂囦欢锛屾枃浠跺悕鏈�濂戒负鑻辨枃銆傛敞鎰忎笅闈㈢殑璺緞锛屼互绗旇�呰嚜宸辩殑鏁版嵁搴撲负渚嬶紝鏁版嵁搴撳畨瑁呭湪D鐩樹笅mysql\mysql涓嬶紝澶囦唤浣嶇疆鍦‵:\beifen锛屽悗闈㈢殑浠g爜鏄棩鏈焄7]聽 銆�
@echo off[8]
color 0D
MODE con: COLS=71 LINES=25
title mysql鏁版嵁搴撹嚜鍔ㄥ浠借剼鏈�(浠诲姟璁″垝)--鑴氭湰浣滆�咃細http://www銆�***銆俢om
set sou_dir="D:\mysql\Mysql\data"
set obj_dir=F:\beifen\%date:~0,10%
net stop mysql
md %obj_dir%
xcopy /e /y %sou_dir% %obj_dir%
net start mysql
@echo off&setlocal enabledelayedexpansion
call:D,30
echo. 30澶╁墠鏃ユ湡涓猴細%D%
echo. 鍒犻櫎30澶╀互鍓嶅浠�......
if exist F:\beifen\%D% rd /s /q F:\beifen\%D%
echo 鑷姩澶囦唤瀹屾垚锛岀▼搴忓皢鑷姩閫�鍑�......
杩樺師/瀵煎叆
杩樺師/瀵煎叆鏁版嵁搴揫9]聽 锛屽鍏ヨ繃绋嬶紝杩涘叆 mysql 鏁版嵁搴撴帶鍒跺彴锛屽 mysql -u root -p
mysql>use 鏁版嵁搴�
鐒跺悗浣跨敤 source 鍛戒护锛屽悗闈㈠弬鏁颁负鑴氭湰鏂囦欢(濡傝繖閲岀敤鍒扮殑.sql)
mysql>source d:\dbname.sql
濡傛灉鎻愮ず鎵句笉鍒版枃浠讹紝杈撳畬 source 鍚庯紝鍙互鐢ㄩ紶鏍囨妸鏂囦欢鐩存帴鎷栬繘鍛戒护琛岀獥鍙�
鍚姩璺熻釜鏂囦欢
mysqld --debug
鍏抽棴鏈嶅姟鍣�
mysqladmin -u root shutdown
鍚姩MySQL鏈嶅姟
mysqld --console
瀹夊叏璁剧疆缂栬緫
涓�銆佸唴閮ㄥ畨鍏ㄦ��-淇濊瘉鏁版嵁鐩綍璁块棶鐨勫畨鍏�
1锛�1鏁版嵁搴撴枃浠躲��
1锛�2鏃ュ織鏂囦欢銆�
浜屻�佸閮ㄥ畨鍏ㄦ��-淇濊瘉缃戠粶璁块棶鐨勫畨鍏�
2锛�1 MySQL 鎺堟潈琛ㄧ殑缁撴瀯鍜屽唴瀹�
2锛�2 鏈嶅姟鍣ㄦ帶鍒跺鎴疯闂�
2锛�3 閬垮厤鎺堟潈琛ㄩ闄�
2锛�4 涓嶇敤 GRANT璁剧疆鐢ㄦ埛
绠$悊宸ュ叿缂栬緫
鍙互浣跨敤鍛戒护琛屽伐鍏风鐞� MySQL 鏁版嵁搴擄紙鍛戒护 mysql 鍜� mysqladmin)锛屼篃鍙互浠� MySQL 鐨勭綉绔欎笅杞藉浘褰㈢鐞嗗伐鍏� MySQL Administrator, MySQL Query Browser 鍜� MySQL Workbench銆�
phpMyAdmin鏄敱 php 鍐欐垚鐨� MySQ L璧勬枡搴撶郴缁熺鐞嗙▼绋嬪簭锛岃绠$悊鑰呭彲鐢� Web 鐣岄潰绠$悊 MySQL 璧勬枡搴撱��
phpMyBackupPro涔熸槸鐢� PHP 鍐欐垚鐨勶紝鍙互閫忚繃 Web 鐣岄潰鍒涘缓鍜岀鐞嗘暟鎹簱銆傚畠鍙互鍒涘缓浼� cronjobs锛屽彲浠ョ敤鏉ヨ嚜鍔ㄥ湪鏌愪釜鏃堕棿鎴栧懆鏈熷浠� MySQL 鏁版嵁搴撱��
鍙﹀锛岃繕鏈夊叾浠栫殑 GUI 绠$悊宸ュ叿锛屼緥濡� mysql-front 浠ュ強 ems mysql manager, navicat绛夌瓑銆�
瑙e喅鏂规硶缂栬緫
MySQL 涓枃鎺掑簭閿欒鐨勮В鍐虫柟娉�
鏂规硶1
鍦� MySQL 鏁版嵁搴撲腑锛岃繘琛屼腑鏂囨帓搴忓拰鏌ユ壘鐨勬椂鍊欙紝瀵规眽瀛楃殑鎺掑簭鍜屾煡鎵剧粨鏋滄槸閿欒鐨勩�傝繖绉嶆儏鍐靛湪 MySQL 鐨勫緢澶氱増鏈腑閮藉瓨鍦ㄣ�傚鏋滆繖涓棶棰樹笉瑙e喅锛岄偅涔� MySQL 灏嗘棤娉曞疄闄呭鐞嗕腑鏂囥��
鍑虹幇杩欎釜闂鐨勫師鍥犳槸锛歁ySQL 鍦ㄦ煡璇㈠瓧绗︿覆鏃舵槸澶у皬鍐欎笉鏁忔劅鐨勶紝鍦ㄧ紪缁� MySQL 鏃朵竴鑸互 ISO-8859 瀛楃闆嗕綔涓洪粯璁ょ殑瀛楃闆嗭紝鍥犳鍦ㄦ瘮杈冭繃绋嬩腑涓枃缂栫爜瀛楃澶у皬鍐欒浆鎹㈤�犳垚浜嗚繖绉嶇幇璞★紝涓�绉嶈В鍐虫柟娉曟槸瀵逛簬鍖呭惈涓枃鐨勫瓧娈靛姞涓� "binary" 灞炴�э紝浣夸箣浣滀负浜岃繘鍒舵瘮杈冿紝渚嬪灏� "name char(10)" 鏀规垚 "name char(10)binary"銆�
鏂规硶2
濡傛灉浣犱娇鐢ㄦ簮鐮佺紪璇� MySQL锛屽彲浠ョ紪璇� MySQL 鏃朵娇鐢� --with--charset=gbk 鍙傛暟锛岃繖鏍� MySQL 灏变細鐩存帴鏀寔涓枃鏌ユ壘鍜屾帓搴忎簡銆俒5]
鎺堟潈闂缂栬緫
鎺堟潈鍗忚
MySQL 閬靛畧鐨勪笉鍙槸 GPL 鍗忚锛岃�屾槸鍙屾巿鏉冩ā寮忥紙dual license锛塠10]聽 鍗充綘鍦ㄩ伒瀹� GPL 鍗忚鐨勫紑婧愰」鐩娇鐢� MySQL锛岄渶瑕侀伒瀹� GPL 鍗忚鏂硅兘浣跨敤銆傚鏋滀綘鍦ㄩ潪寮�婧愰」鐩娇鐢紙鍗宠蒋浠朵笉鎵撶畻寮�鏀炬簮浠g爜锛夛紝涓旇杞欢鐢ㄦ潵閿�鍞紝鍒欓渶瑕佸悜 MySQL 鏀粯鐩稿簲 license 璐圭敤銆俒11]
鏂囦欢鎵嬪唽bug
鍦� 5.5.31 鐗堟湰鏃朵汉浠彂鐜� Oracle 鍙栨秷浜嗗叾涓殑 GPL 鍗忚锛岄�犳垚浜嗕竴瀹氱殑涓嶅畨銆傛湁寮�鍙戣�呭湪 MySQL 绋嬪簭鑷櫕缃戠珯涓婁妇鎶ヨ繖椤规巿鏉冮敊璇棶棰橈紝闅忓嵆 MySQL 宸ョ▼鏈嶅姟鎬荤洃 Yngve Svendsen 鍦ㄧ綉绔欎笂鍧﹁█锛岃繖鐨勭‘鏄竴涓枃浠惰嚟铏紝鍥犱负 man 鎵嬪唽绋嬪簭閲嶆柊缂栬瘧鏃跺鐢ㄤ簡閿欒鐨勬巿鏉冨唴瀹广�俒12]聽 涓嶈繃浠嶇劧鏈変汉璁や负锛孫racle 鍙栨秷寮�婧愭巿鏉冩敼閲囧晢涓氭巿鏉冪殑鈥滆繖涓�澶╄繜鏃╂槸瑕佸埌鏉ョ殑鈥濓紝骞跺姹傚叾浠栦唬鏇挎柟妗堛�俒13]
瀹夎 MySQL 5.5缂栬緫
1銆佽繍琛� mysql 瀹夎鏂囦欢锛�
2銆佹寜 Next锛岀劧鍚庨�夋嫨瀹夎鏂瑰紡锛屾湁 "Typical锛堥粯璁わ級"銆�"Complete锛堝畬鍏級"銆�"Custom锛堢敤鎴疯嚜瀹氫箟锛�"锛岄�夋嫨绗簩涓�夐」 "Custom"锛屼笅涓�姝�, MySQL Server (mysql鏈嶅姟鍣�), Developer Components (寮�鍙戣�呴儴鍒�), Debug Symbols (璋冭瘯绗﹀彿), Server data files (鏈嶅姟鍣ㄦ暟鎹枃浠�) 榛樿锛�
3銆佹敼鍙樺畨瑁呰矾寰勶紱鍘熻矾寰勬槸"C:\Program Files\MySQL\MySQL Server 5.5\"锛屼篃鍙互淇敼涓猴細"E:\Program Files\MySQL Server 5.5\"銆備笅涓�姝�,瀹夎,浼氬脊鍑虹獥鍙�,鐐逛笅涓�姝�,鍐嶇偣涓嬩竴姝�,閫夋嫨"Launch the MySql instance Configuration Wizard"锛屾剰鎬濇槸鍚姩MySQL瀹炰緥閰嶇疆鍚戝,鍐嶇偣鍑籉inish,鍐嶇偣涓嬩竴姝�,Detailed Configuration锛堣缁嗛厤缃級鍜孲tandard Configuration锛堟爣鍑嗛厤缃級锛岄�夋嫨璇︾粏閰嶇疆锛屼笅涓�姝ワ紱
4銆侀�夋嫨鏈嶅姟鍣ㄧ被鍨嬶紝"Developer Machine锛堝紑鍙戞祴璇曠被锛宮ysql鍗犵敤寰堝皯璧勬簮锛�"銆�"Server Machine锛堟湇鍔″櫒绫诲瀷锛宮ysql鍗犵敤杈冨璧勬簮锛�"銆�"DedicatedMySQL Server Machine锛堜笓闂ㄧ殑鏁版嵁搴撴湇鍔″櫒锛宮ysql鍗犵敤鎵�鏈夊彲鐢ㄨ祫婧愶級"锛屾牴鎹嚜宸辩殑绫诲瀷閫夋嫨锛屾祴璇曡蒋浠堕��"Developer Machine"锛屾湇鍔″櫒閫�"Server Machine"锛屼笅涓�姝ワ紱
5銆侀�夋嫨鍒涘缓 MySQL琛ㄦ椂浣跨敤鐨勮〃澶勭悊鍣紝"Multifunctional Database"锛堥�氱敤澶氬姛鑳藉瀷锛屽ソ,鍚屾椂浣跨敤InnoDB鍜� MyISAM 鍌ㄥ瓨寮曟搸锛夈��"Transactional Database Only"锛堟湇鍔″櫒绫诲瀷锛屼笓娉ㄤ簬浜嬪姟澶勭悊锛屼富瑕佷娇鐢� InnoDB 鍙伓灏斾娇鐢� MyISAM锛屼竴鑸級銆�"Non-Transactional DatabaseOnly"锛堥潪浜嬪姟澶勭悊鍨嬶紝杈冪畝鍗曪紝瀹屽叏绂佺敤 InnoDB 鍌ㄥ瓨寮曟搸锛屽皢鎵�鏈夋湇鍔″櫒璧勬簮鎸囨淳缁� MyISAM 鍌ㄥ瓨寮曟搸锛夛紝闅忚嚜宸辩殑鐢ㄩ�旇�岄�夋嫨銆俒14]
鏇夸唬鏂规缂栬緫
闅忕潃 MySQL 琚� Oracle 鏀惰喘锛孧ySQL 鐨勭敤鎴峰拰寮�鍙戣�呭紑濮嬭川鐤戝紑婧愭暟鎹簱鐨勫懡杩愶紝涓庢鍚屾椂浠栦滑寮�濮嬪鎵炬浛浠e搧銆�
鏈夋枃绔犲啓鍒颁簡鏀惧純 MySQL 鐨勪簲澶х悊鐢憋細[15]
MySQL 涓嶅鍏跺畠鍏崇郴鍨嬫暟鎹簱绠$悊绯荤粺閭f牱鎴愮啛锛�
MySQL 鏄紑婧愮殑...浣嗗彧鏈夎繎浼艰�屽凡锛�
MySQL 鐨勬�ц兘鏃犳硶涓庣珵浜夊鎵嬬浉鎻愬苟璁猴紱
MySQL 鏄� Oracle 鎵�鏈夌殑锛岃�屼笉鏄ぞ鍖洪┍鍔ㄧ殑锛�
瓒婃潵瓒婂鐨勫己鍔插鎵嬨��
MariaDB
浠� MySQL 杞悜 MariaDB鐨勪唬琛ㄥ巶瀹讹細璋锋瓕锛�2013骞�9鏈堬級銆丷edHat锛�2013骞�6鏈堬級銆佺淮鍩虹櫨绉戯紙2013骞�4鏈堬級
MySQL 鍦� 2008 骞磋Sun浠�10浜跨編閲戞墍鏀惰喘锛孧ySQL 鍒涘浜� Michael Widenius 鍒欎笉婊� Sun 寮�鍙戝洟闃熻剼姝ヨ繃鎱紝鎰よ�岀鑱屾垚绔嬪紑婧愭暟鎹簱鑱旂洘锛屽彟澶栦粠鐜版湁 MySQL 绋嬪簭浠g爜涓紝寮�鍙戝嚭鍙︿竴涓欢浼稿垎鏀増鏈紝涔熷氨鏄悕涓虹帥鑾変簹鏁版嵁搴撶殑浼佷笟绾у紑婧愭暟鎹簱[13]聽 銆�
鐜涜帀浜氭暟鎹簱濡傚悓 MySQL 鐨勫奖瀛愮増鏈紝鐜涜帀浜氭暟鎹簱鏄� MySQL 鐨勪竴涓垎鏀増鏈紙branch锛夛紝鑰屼笉鏄鐢熺増鏈紙folk锛夛紝鎻愪緵鐨勫姛鑳藉彲鍜� MySQL 瀹屽叏鍏煎銆�
PostgreSQL
浠� MySQL 杞悜 PostgreSQL鐨勪唬琛ㄥ巶瀹讹細鑻规灉锛�2011骞达級
PostgreSQL鏄竴涓嚜鐢辩殑瀵硅薄-鍏崇郴鏁版嵁搴撴湇鍔″櫒(鏁版嵁搴撶鐞嗙郴缁�)銆侾ostgreSQL鏀寔澶ч儴鍒� SQL鏍囧噯骞朵笖鎻愪緵浜嗚澶氬叾浠栫幇浠g壒鎬э細澶嶆潅鏌ヨ銆佸閿�佽Е鍙戝櫒銆佽鍥俱�佷簨鍔″畬鏁存�с�丮VCC銆傚悓鏍凤紝PostgreSQL 鍙互鐢ㄨ澶氭柟娉曟墿灞曪紝姣斿锛� 閫氳繃澧炲姞鏂扮殑鏁版嵁绫诲瀷銆佸嚱鏁般�佹搷浣滅銆佽仛闆嗗嚱鏁般�佺储寮曟柟娉曘�佽繃绋嬭瑷�銆傚苟涓旓紝鍥犱负璁稿彲璇佺殑鐏垫椿锛屼换浣曚汉閮藉彲浠ヤ互浠讳綍鐩殑鍏嶈垂浣跨敤銆佷慨鏀广�佸拰鍒嗗彂 PostgreSQL锛屼笉绠℃槸绉佺敤銆佸晢鐢ㄣ�佽繕鏄鏈爺绌朵娇鐢ㄣ��
PostgreSQL 涔熷彈 NoSQL 鎬濇兂鐨勫惎鍙戯紝甯屾湜鑳藉鍦ㄤ粖鍚庡彲浠ョ粰浣跨敤鑰呮洿澶氬彲瀹氬埗鍙皟鑺傜殑鍔熻兘锛堜笉鏄杩欎釜鎴愮啛鐨勫叧绯绘�ф暟鎹簱绯荤粺瑕佸悜 NoSQL 杞彉锛夈��
NoSQL
NoSQL(NoSQL = Not Only SQL)锛屾剰鍗斥�滀笉浠呬粎鏄� SQL鈥濓紝鏄竴椤瑰叏鏂扮殑鏁版嵁搴撻潻鍛芥�ц繍鍔ㄣ�侼oSQL鎸囩殑鏄潪鍏崇郴鍨嬬殑鏁版嵁搴撱�傞殢鐫�浜掕仈缃� web2.0缃戠珯鐨勫叴璧凤紝浼犵粺鐨勫叧绯绘暟鎹簱鍦ㄥ簲浠� web2.0 缃戠珯锛岀壒鍒槸瓒呭ぇ瑙勬ā鍜岄珮骞跺彂鐨� SNS 绫诲瀷鐨� web2.0 绾姩鎬佺綉绔欏凡缁忔樉寰楀姏涓嶄粠蹇冿紝鏆撮湶浜嗗緢澶氶毦浠ュ厠鏈嶇殑闂锛岃�岄潪鍏崇郴鍨嬬殑鏁版嵁搴撳垯鐢变簬鍏舵湰韬殑鐗圭偣寰楀埌浜嗛潪甯歌繀閫熺殑鍙戝睍銆�
鍏朵唬琛ㄧ殑寮�婧愯蒋浠跺锛歁embase銆丮ongoDB銆丠ypertable銆丄pache Cassandra銆丆ouchDB绛夈��
Oracle 鍏嶈垂鐗�
Oracle鑷� Oracle 10g 鍚庢帹鍑哄搴旂殑鍏嶈垂鐗堛��
杩滅▼璁块棶 MySQL缂栬緫
1锛氬皢 localhost 鏀规垚 "%"
淇敼 "mysql" 鏁版嵁搴撻噷鐨� "user" 琛ㄩ噷鐨� "host" 椤癸紝灏�"localhost"鏀规垚"%"
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>FLUSH PRIVILEGES;
2锛氫娇鐢� myuser/mypassword 浠庝换浣曚富鏈鸿繛鎺ュ埌 mysql 鏈嶅姟鍣�:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
浣跨敤myuser/mypassword浠巌p涓�192.168.225.166鐨勪富鏈鸿繛鎺ュ埌mysql鏈嶅姟鍣�:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.225.166' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
3锛氭硾鎺堟潈
mysql -h localhost -u root
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; //璧嬩簣浠讳綍涓绘満涓婁互root韬唤璁块棶鏁版嵁鐨勬潈闄�
mysql>FLUSH PRIVILEGES;[16]
MySQL Server 鏂扮壒鎬х紪杈�
琛ㄥ拰绱㈠紩鐨勫垎鍖�
琛岀骇澶嶅埗
MySQL 鍩虹兢鍩轰簬纾佺洏鐨勬暟鎹敮鎸�
MySQL 闆嗙兢澶嶅埗
澧炲己鐨勫叏鏂囨湰鎼滅储鍑芥暟
澧炲己鐨勪俊鎭ā寮�(鏁版嵁瀛楀吀)
鍙彃鍏ョ殑 API
鏈嶅姟鍣ㄦ棩蹇楄〃
XML锛堟爣鍑嗛�氱敤鏍囪璇█鐨勫瓙闆嗭級/ XPath鏀寔
瀹炰緥绠$悊鍣�
琛ㄧ┖闂村浠�
mysql_upgrade 鍗囩骇绋嬪簭
鍐呴儴浠诲姟/浜嬩欢璋冨害鍣�
鏂扮殑鎬ц兘宸ュ叿鍜岄�夐」濡� mysqlslap[3]
MySQL PHP 璇硶
MySQL 鍙簲鐢ㄤ簬澶氱璇█锛屽寘鎷� PERL, C, C++, JAVA 鍜� PHP銆� 鍦ㄨ繖浜涜瑷�涓紝MySQL 鍦� PHP 鐨� web 寮�鍙戜腑鏄簲鐢ㄦ渶骞挎硾銆�
鍦ㄦ湰鏁欑▼涓垜浠ぇ閮ㄥ垎瀹炰緥閮介噰鐢ㄤ簡PHP璇█銆傚鏋滀綘鎯充簡瑙� MySQL 鍦� PHP 涓殑搴旂敤锛屽彲浠ヨ闂垜浠殑PHP 涓娇鐢� MySQL 浠嬬粛銆�
PHP 鎻愪緵浜嗗绉嶆柟寮忔潵璁块棶鍜屾搷浣� MySQL 鏁版嵁搴撹褰曘�侾HP MySQL 鍑芥暟鏍煎紡濡備笅锛�
mysql_function(value,value,...);
浠ヤ笂鏍煎紡涓璮unction閮ㄥ垎鎻忚堪浜唌ysql鍑芥暟鐨勫姛鑳斤紝濡�
mysqli_connect($connect);
mysqli_query($connect,"SQLstatement");
mysql_fetch_array()
mysql_connect(),mysql_close()
浠ヤ笅瀹炰緥灞曠ず浜哖HP璋冪敤mysql鍑芥暟鐨勮娉曪細