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

Chapter聽14.聽Pluggable Storage Engine Architecture - MySQL 5.1参考手册中文版

绗14绔狅細鎻掍欢寮忓瓨鍌ㄥ紩鎿庝綋绯荤粨鏋

14.1. 鍓嶈█

MySQL 5.1涓紝MySQL AB寮曞叆浜嗘柊鐨勬彃浠跺紡瀛樺偍寮曟搸浣撶郴缁撴瀯锛屽厑璁稿皢瀛樺偍寮曟搸鍔犺浇鍒版鍦ㄨ繍鏂扮殑MySQL鏈嶅姟鍣ㄤ腑銆

鏈珷浠嬬粛浜嗘彃浠跺紡瀛樺偍寮曟搸浣撶郴缁撴瀯锛屾瑕佷粙缁嶄簡涓MySQL涓璧锋彁渚涚殑鍚勭瀛樺偍寮曟搸锛屼粙缁嶄簡灏嗗瓨鍌ㄥ紩鎿庤祴缁欒〃鐨勬柟娉曪紝浠ュ強鎻掑叆鍜屾嫈鍑哄瓨鍌ㄥ紩鎿庣殑鏂规硶銆

14.2. 姒傝堪

浣跨敤MySQL鎻掍欢寮忓瓨鍌ㄥ紩鎿庝綋绯荤粨鏋勶紝鍏佽鏁版嵁搴撲笓涓氫汉鍛樹负鐗瑰畾鐨勫簲鐢ㄩ渶姹傞夋嫨涓撻棬鐨勫瓨鍌ㄥ紩鎿庯紝瀹屽叏涓嶉渶瑕佺鐞嗕换浣曠壒娈婄殑搴旂敤缂栫爜瑕佹眰銆傞噰鐢MySQL鏈嶅姟鍣ㄤ綋绯荤粨鏋勶紝鐢变簬鍦ㄥ瓨鍌ㄧ骇鍒笂鎻愪緵浜嗕竴鑷村拰绠鍗曠殑搴旂敤妯″瀷鍜API锛屽簲鐢ㄧ▼搴忕紪绋嬩汉鍛樺拰DBA鍙笉鍐嶈冭檻鎵鏈夌殑搴曞眰瀹炴柦缁嗚妭銆傚洜姝わ紝灏界涓嶅悓鐨勫瓨鍌ㄥ紩鎿庡叿鏈変笉鍚岀殑鑳藉姏锛屽簲鐢ㄧ▼搴忔槸涓庝箣鍒嗙鐨勩

鍦ㄤ笅鍥句腑锛屼互鍥惧舰鏂瑰紡浠嬬粛浜MySQL鎻掍欢寮忓瓨鍌ㄥ紩鎿庝綋绯荤粨鏋勶細

鍥14.1锛歁ySQL鎻掍欢寮忓瓨鍌ㄥ紩鎿庣殑浣撶郴缁撴瀯

The MySQL pluggable storage engine
          architecture

鎻掍欢寮忓瓨鍌ㄥ紩鎿庝綋绯荤粨鏋勬彁渚涗簡鏍囧噯鐨勭鐞嗗拰鏀寔鏈嶅姟闆嗗悎锛屽畠浠鎵鏈夌殑鍩烘湰瀛樺偍寮曟搸鏉ヨ鏄叡鍚岀殑銆傚瓨鍌ㄥ紩鎿庢湰韬槸鏁版嵁搴撴湇鍔″櫒鐨勭粍浠讹紝璐熻矗瀵瑰湪鐗╃悊鏈嶅姟鍣ㄥ眰闈笂缁存姢鐨勫熀鏈暟鎹繘琛屽疄闄呮搷浣溿

杩欐槸涓绉嶉珮鏁堢殑妯″潡鍖栦綋绯荤粨鏋勶紝瀹冧负閭d簺甯屾湜涓撴敞浜庣壒瀹氬簲鐢ㄩ渶姹傜殑浜哄憳鎻愪緵浜嗗法澶х殑渚垮埄鍜岀泭澶勶紝杩欑被鐗规畩搴旂敤闇姹傚寘鎷暟鎹粨鍌ㄣ佷簨鍔″鐞嗐侀珮鍙敤鎬ф儏褰㈢瓑锛屽悓鏃惰繕鑳藉埄鐢ㄧ嫭绔嬩簬浠讳綍瀛樺偍寮曟搸鐨勪竴缁勬帴鍙e拰鏈嶅姟銆

搴旂敤绋嬪簭缂栫▼浜哄憳鍜DBA閫氳繃浣嶄簬瀛樺偍寮曟搸涔嬩笂鐨勮繛鎺ュ櫒API鍜屾湇鍔″眰鏉ュ鐞MySQL鏁版嵁搴撱傚鏋滃簲鐢ㄧ▼搴忕殑鍙樺寲闇瑕佹敼鍙樺簳灞傚瓨鍌ㄥ紩鎿庯紝鎴栭渶瑕佸鍔1涓垨澶氫釜棰濆鐨勫瓨鍌ㄥ紩鎿庝互鏀寔鏂扮殑闇姹傦紝涓嶉渶瑕佽繘琛屽ぇ鐨勭紪鐮佹垨杩涚▼鏇存敼灏辫兘瀹炵幇杩欑被瑕佹眰銆MySQL鏈嶅姟鍣ㄤ綋绯荤粨鏋勬彁渚涗簡涓鑷村拰鏄撲簬浣跨敤鐨API锛岃繖绫API閫傜敤浜庡绉嶅瓨鍌ㄥ紩鎿庯紝閫氳繃璇ユ柟寮忥紝璇ョ粨鏋勫皢搴旂敤绋嬪簭涓庡瓨鍌ㄥ紩鎿庣殑搴曞眰澶嶆潅鎬ч殧绂诲紑鏉ャ

14.3. 鍏叡MySQL鏁版嵁搴撴湇鍔″櫒灞

MySQL鎻掍欢寮忓瓨鍌ㄥ紩鎿庢槸MySQL鏁版嵁搴撴湇鍔″櫒涓殑缁勪欢锛岃礋璐d负鏁版嵁搴撴墽琛屽疄闄呯殑鏁版嵁I/O鎿嶄綔锛屽苟鑳藉厑璁稿拰寮哄埗鎵ц闈㈠悜鐗规畩搴旂敤闇姹傜殑鐗瑰畾鐗规ч泦鍚堛備娇鐢ㄧ壒娈婂瓨鍌ㄥ紩鎿庣殑涓昏浼樼偣涔嬩竴鍦ㄤ簬锛屼粎闇鎻愪緵鐗规畩搴旂敤鎵闇鐨勭壒鎬э紝鍥犳锛屾暟鎹簱涓殑绯荤粺寮閿杈冨皬锛屾渶缁堢粨鏋滃叿鏈夋洿鏈夋晥鍜屾洿楂樼殑鏁版嵁搴撴ц兘銆傝繖涔熸槸MySQL琚缁堣涓哄叿鏈夐珮鎬ц兘鐨勫師鍥犱箣涓锛屽湪琛屼笟鏍囧噯鍩哄噯鏂归潰锛屽畠鑳藉尮鏁屾垨鍑昏触涓撴湁鐨勬暣浣撳紡鏁版嵁搴撱

浠庢妧鏈搴︿笂鐪嬶紝鍦ㄥ瓨鍌ㄥ紩鎿庝腑锛屼竴浜涚嫭鐗圭殑鏀寔搴曞眰缁撴瀯鐨勭粍浠舵槸浠涔堝憿锛熶竴浜涘叧閿樊鍒寘鎷細

         骞跺彂鎬э細鏌愪簺搴旂敤绋嬪簭姣斿叾浠栧簲鐢ㄧ▼搴忓叿鏈夊緢澶氱殑棰楃矑绾ч攣瀹氳姹傦紙濡傝绾ч攣瀹氾級銆傞夋嫨姝g‘鐨勯攣瀹氱瓥鐣ヨ兘澶熷噺灏戝紑閿锛屽苟鏈夊姪浜庢暣浣撴ц兘鐨勬彁鍗囥傚畠杩樺寘鎷澶氱鑳藉姏鐨勬敮鎸侊紝濡傚鐗堟湰骞跺彂鎬ф帶鍒舵垨鈥滃揩鐓р濊鍙栫瓑銆

         浜嬪姟鏀寔锛氬苟闈炴墍鏈夌殑搴旂敤绋嬪簭閮介渶瑕佷簨鍔★紝浣嗗鐨勭‘闇瑕佷簨鍔$殑搴旂敤绋嬪簭鏉ヨ锛屾湁鐫瀹氫箟鑹ソ鐨勯渶姹傦紝濡ACID鍏煎绛夈

         寮曠敤瀹屾暣鎬э細閫氳繃DDDL瀹氫箟鐨 澶栭敭锛屾湇鍔″櫒闇瑕佸己鍒朵繚鎸佸叧鑱旀暟鎹簱鐨勫紩鐢ㄥ畬鏁存с

         鐗╃悊瀛樺偍锛氬畠鍖呮嫭鍚勭鍚勬牱鐨勪簨椤癸紝浠庤〃鍜岀储寮曠殑鎬荤殑椤靛ぇ灏忥紝鍒板瓨鍌ㄦ暟鎹墍闇鐨勬牸寮忥紝鍒扮墿鐞嗙鐩樸

         绱㈠紩鏀寔锛氫笉鍚岀殑搴旂敤绋嬪簭鍊惧悜浜庨噰鐢ㄤ笉鍚岀殑绱㈠紩绛栫暐锛屾瘡绉嶅瓨鍌ㄥ紩鎿庨氬父鏈夎嚜宸辩殑缂栧埗绱㈠紩鏂规硶锛屼絾鏌愪簺绱㈠紩鏂规硶锛堝B-tree绱㈠紩锛夊鍑犱箮鎵鏈夌殑瀛樺偍寮曟搸鏉ヨ鏄叡鍚岀殑銆

         鍐呭瓨楂橀熺紦鍐诧細涓庡叾浠栧簲鐢ㄧ▼搴忕浉姣旓紝涓嶅悓鐨勫簲鐢ㄧ▼搴瀵规煇浜涘唴瀛橀珮閫熺紦鍐茬瓥鐣ョ殑鍝嶅簲鏇村ソ锛屽洜姝わ紝灏界鏌愪簺鍐呭瓨楂橀熺紦鍐插鎵鏈夊瓨鍌ㄥ紩鎿庢潵璇存槸鍏卞悓鐨勶紙濡傜敤浜庣敤鎴疯繛鎺ョ殑楂橀熺紦鍐诧紝MySQL鐨勯珮閫熸煡璇㈤珮閫熺紦鍐茬瓑锛夛紝鍏朵粬楂橀熺紦鍐茬瓥鐣ヤ粎褰撲娇鐢ㄧ壒娈婄殑瀛樺偍寮曟搸鏃舵墠鍞竴瀹氫箟銆

         鎬ц兘甯姪锛鍖呮嫭閽堝骞惰鎿嶄綔鐨勫I/O绾跨▼锛岀嚎绋嬪苟鍙戞э紝鏁版嵁搴撴鏌ョ偣锛屾垚鎵规彃鍏ュ鐞嗙瓑銆

         鍏朵粬鐩爣鐗规э細鍙兘鍖呮嫭瀵瑰湴鐞嗙┖闂存搷浣滅殑鏀寔锛屽鐗瑰畾鏁版嵁澶勭悊鎿嶄綔鐨勫畨鍏ㄩ檺鍒剁瓑銆

姣忕粍鎻掍欢寮忓瓨鍌ㄥ紩鎿庡熀鏈粍浠跺潎閲囩敤浜嗙浉搴旂殑璁捐锛岃兘澶熶负鐗瑰畾搴旂敤鎻愪緵鍙夋嫨鐨勭壒鎬ч泦鍚堛備粠鍙嶉潰瑙掑害鐪嬶紝閬垮厤浣跨敤缁勪欢鐗规ч泦鍚堟湁鍔╀簬閬垮厤涓嶅繀瑕佺殑寮閿銆傚洜姝わ紝鏄捐屾槗瑙侊紝搴旂悊瑙g壒瀹氬簲鐢ㄧ▼搴忕殑闇姹傞泦鍚堬紝骞堕夋嫨鎭板綋鐨勮兘澶у箙搴︽敼鍠勭郴缁熸暣浣撴晥鐜囧拰鎬ц兘鐨MySQL瀛樺偍寮曟搸銆

14.4. 閫夋嫨瀛樺偍寮曟搸

MySQL涓璧锋彁渚涚殑鍚勭瀛樺偍寮曟搸鍦ㄨ璁℃椂鑰冭檻浜嗕笉鍚岀殑浣跨敤鎯呭喌銆備负浜嗘洿鏈夋晥鍦颁娇鐢ㄦ彃浠跺紡瀛樺偍浣撶郴缁撴瀯锛屾渶濂戒簡瑙e悇绉嶅瓨鍌ㄥ紩鎿庣殑浼樼偣鍜岀己鐐广

鍦ㄤ笅闈㈢殑琛ㄦ牸涓紝姒傝浠嬬粛浜嗕笌MySQL涓璧锋彁渚涚殑瀛樺偍寮曟搸锛

鍥14.2锛氬瓨鍌ㄥ紩鎿庢瘮杈

Storage engine comparison

涓嬭堪瀛樺偍寮曟搸鏄渶甯哥敤鐨勶細

         MyISAM锛氶粯璁ょ殑MySQL鎻掍欢寮忓瓨鍌ㄥ紩鎿庯紝瀹冩槸鍦Web銆佹暟鎹粨鍌ㄥ拰鍏朵粬搴旂敤鐜涓嬫渶甯镐娇鐢ㄧ殑瀛樺偍寮曟搸涔嬩竴銆傛敞鎰忥紝閫氳繃鏇存敼STORAGE_ENGINE閰嶇疆鍙橀噺锛岃兘澶熸柟渚垮湴鏇存敼MySQL鏈嶅姟鍣ㄧ殑榛樿瀛樺偍寮曟搸銆

         InnoDB锛氱敤浜庝簨鍔″鐞嗗簲鐢ㄧ▼搴忥紝鍏锋湁浼楀鐗规э紝鍖呮嫭ACID浜嬪姟鏀寔銆

         BDB锛氬彲鏇夸唬InnoDB鐨勪簨鍔″紩鎿庯紝鏀寔COMMITROLLBACK鍜屽叾浠栦簨鍔$壒鎬с

         Memory锛氬皢鎵鏈夋暟鎹繚瀛樺湪RAM涓紝鍦ㄩ渶瑕佸揩閫熸煡鎵惧紩鐢ㄥ拰鍏朵粬绫讳技鏁版嵁鐨勭幆澧冧笅锛屽彲鎻愪緵鏋佸揩鐨勮闂

         Merge锛氬厑璁MySQL DBA鎴栧紑鍙戜汉鍛樺皢涓绯诲垪绛夊悓鐨MyISAM琛ㄤ互閫昏緫鏂瑰紡缁勫悎鍦ㄤ竴璧凤紝骞朵綔涓1涓璞″紩鐢ㄥ畠浠傚浜庤濡傛暟鎹粨鍌ㄧ瓑VLDB鐜鍗佸垎閫傚悎銆

         Archive锛氫负澶ч噺寰堝皯寮曠敤鐨勫巻鍙层佸綊妗c佹垨瀹夊叏瀹¤淇℃伅鐨勫瓨鍌ㄥ拰妫绱㈡彁渚涗簡瀹岀編鐨勮В鍐虫柟妗堛

         Federated锛氳兘澶熷皢澶氫釜鍒嗙鐨MySQL鏈嶅姟鍣ㄩ摼鎺ヨ捣鏉ワ紝浠庡涓墿鐞嗘湇鍔″櫒鍒涘缓涓涓昏緫鏁版嵁搴撱傚崄鍒嗛傚悎浜庡垎甯冨紡鐜鎴栨暟鎹泦甯傜幆澧冦

         Cluster/NDBMySQL鐨勭皣寮忔暟鎹簱寮曟搸锛屽挨鍏堕傚悎浜庡叿鏈夐珮鎬ц兘鏌ユ壘瑕佹眰鐨勫簲鐢ㄧ▼搴忥紝杩欑被鏌ユ壘闇姹傝繕瑕佹眰鍏锋湁鏈楂樼殑姝e父宸ヤ綔鏃堕棿鍜屽彲鐢ㄦс

         Other锛氬叾浠栧瓨鍌ㄥ紩鎿庡寘鎷CSV锛堝紩鐢ㄧ敱閫楀彿闅斿紑鐨勭敤浣滄暟鎹簱琛ㄧ殑鏂囦欢锛夛紝Blackhole锛堢敤浜庝复鏃剁姝㈠鏁版嵁搴撶殑搴旂敤绋嬪簭杈撳叆锛夛紝浠ュ強Example寮曟搸锛堝彲涓哄揩閫熷垱寤哄畾鍒剁殑鎻掍欢寮忓瓨鍌ㄥ紩鎿庢彁渚涘府鍔╋級銆

璇疯浣忥紝瀵逛簬鏁翠釜鏈嶅姟鍣ㄦ垨鏂规锛屼綘骞朵笉涓瀹氳浣跨敤鐩稿悓鐨勫瓨鍌ㄥ紩鎿庯紝浣犲彲浠ヤ负鏂规涓殑姣忎釜琛ㄤ娇鐢ㄤ笉鍚岀殑瀛樺偍寮曟搸锛岃繖鐐瑰緢閲嶈銆

鍏充簬MySQL涓墍鍖呭惈瀛樺偍寮曟搸鐨勮缁嗕俊鎭紝璇峰弬瑙14.4鑺傦紝鈥滈夋嫨瀛樺偍寮曟搸鈥

14.5. 灏嗗瓨鍌ㄥ紩鎿庢寚瀹氱粰琛

鍙互鍦ㄥ垱寤烘柊琛ㄦ椂鎸囧畾瀛樺偍寮曟搸锛屾垨閫氳繃浣跨敤ALTER TABLE璇彞鎸囧畾瀛樺偍寮曟搸銆

瑕佹兂鍦ㄥ垱寤鸿〃鏃舵寚瀹氬瓨鍌ㄥ紩鎿庯紝鍙娇鐢ENGINE鍙傛暟锛

CREATE TABLE engineTest(
id INT
) ENGINE = MyISAM;

瑕佹兂鏇存敼宸叉湁琛ㄧ殑瀛樺偍寮曟搸锛屽彲浣跨敤ALTER TABLE璇彞锛

ALTER TABLE engineTest ENGINE = ARCHIVE;

14.6. 瀛樺偍寮曟搸鍜屼簨鍔

涓嬭堪瀛樺偍寮曟搸鏀寔浜嬪姟锛

         InnoDB锛氶氳繃MVCC鏀寔浜嬪姟锛屽厑璁COMMITROLLBACK鍜屼繚瀛樼偣銆

         NDB锛氶氳繃MVCC鏀寔浜嬪姟锛屽厑璁COMMITROLLBACK

         BDB锛氭敮鎸佷簨鍔★紝鍏佽COMMITROLLBACK

14.7. 鎻掑叆瀛樺偍寮曟搸

鑳藉浣跨敤瀛樺偍寮曟搸涔嬪墠锛屽繀椤讳娇鐢INSTALL PLUGIN璇彞灏嗗瓨鍌ㄥ紩鎿plugin锛堟彃浠讹級瑁呰浇鍒mysql銆備緥濡傦紝瑕佹兂鍔犺浇example寮曟搸锛岄鍏堝簲鍔犺浇ha_example.so妯″潡锛
INSTALL PLUGIN ha_example SONAME 'ha_example.so';

鏂囦欢.so蹇呴』浣嶄簬MySQL鏈嶅姟鍣ㄥ簱鐩綍涓嬶紙鍏稿瀷鎯呭喌涓嬫槸installdir/lib锛夈

14.8. 鎷斿嚭瀛樺偍寮曟搸

瑕佹兂鎷斿嚭瀛樺偍寮曟搸锛屽彲浣跨敤UNINSTALL PLUGIN璇彞锛

UNINSTALL PLUGIN ha_example;

濡傛灉鎷斿嚭浜嗘琚凡鏈夎〃浣跨敤鐨勫瓨鍌ㄥ紩鎿庯紝杩欎簺琛ㄥ皢鎴愪负涓嶅彲璁块棶鐨勩傛嫈鍑哄瓨鍌ㄥ紩鎿庝箣鍓嶏紝璇风‘淇濇病鏈変换浣曡〃浣跨敤璇ュ瓨鍌ㄥ紩鎿庛

14.9. 鎻掍欢寮忓瓨鍌ㄥ櫒鐨勫畨鍏ㄥ惈涔

涓轰簡瀹夎鎻掍欢寮忓瓨鍌ㄥ紩鎿庯紝plugin鏂囦欢蹇呴』浣嶄簬鎭板綋鐨MySQL搴撶洰褰曚笅锛岃屼笖鍙戝嚭INSTALL PLUGIN璇彞鐨勭敤鎴峰繀椤诲叿鏈SUPER鏉冮檺銆


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