鏁版嵁搴撲紭鍖栫殑鎬濊矾
Posted 娓摜鐨勭瑪璁?/a> 鏁版
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏁版嵁搴撲紭鍖栫殑鎬濊矾相关的知识,希望对你有一定的参考价值。
瑕佸涔營T缂栫▼(Java,澶ф暟鎹?web,python...)锛孶I璁捐锛屽氨鑱旂郴鎴戝惂
寰俊浜岀淮鐮侌煈?span data-darkmode-bgcolor-15890926107821="rgb(36, 36, 36)" data-darkmode-original-bgcolor-15890926107821="rgb(255, 255, 255)" data-darkmode-color-15890926107821="rgb(255, 76, 0)" data-darkmode-original-color-15890926107821="rgb(255, 76, 0)" data-darkmode-bgcolor-15919478928968="rgb(36, 36, 36)" data-darkmode-original-bgcolor-15919478928968="rgb(255, 255, 255)" data-darkmode-color-15919478928968="rgb(255, 76, 0)" data-darkmode-original-color-15919478928968="rgb(255, 76, 0)" data-darkmode-bgcolor-15923582067807="rgb(36, 36, 36)" data-darkmode-original-bgcolor-15923582067807="rgb(255, 255, 255)" data-darkmode-color-15923582067807="rgb(255, 76, 0)" data-darkmode-original-color-15923582067807="rgb(255, 76, 0)" class="mq-8">馃憜馃憜馃憜馃憜馃憜
鍏嶈垂鍜ㄨ锛屽厤璐硅瘯鍚?/span>
鍓嶈█
鏁版嵁搴撲紭鍖栦竴鏂归潰鏄壘鍑虹郴缁熺殑鐡堕,鎻愰珮mysql鏁版嵁搴撶殑鏁翠綋鎬ц兘,鑰屽彟涓€鏂归潰闇€瑕佸悎鐞嗙殑缁撴瀯璁捐鍜屽弬鏁拌皟鏁?浠ユ彁楂樼敤鎴风殑鐩稿簲閫熷害,鍚屾椂杩樿灏藉彲鑳界殑鑺傜害绯荤粺璧勬簮,浠ヤ究璁╃郴缁熸彁渚涙洿澶х殑璐熻嵎.
1. 浼樺寲涓€瑙堝浘
2. 浼樺寲
绗旇€呭皢浼樺寲鍒嗕负浜嗕袱澶х被,杞紭鍖栧拰纭紭鍖?杞紭鍖栦竴鑸槸鎿嶄綔鏁版嵁搴撳嵆鍙?鑰岀‖浼樺寲鍒欐槸鎿嶄綔鏈嶅姟鍣ㄧ‖浠跺強鍙傛暟璁剧疆.
2.1 杞紭鍖?/span>
2.1.1 鏌ヨ璇彞浼樺寲
1.棣栧厛鎴戜滑鍙互鐢‥XPLAIN鎴朌ESCRIBE(绠€鍐?DESC)鍛戒护鍒嗘瀽涓€鏉℃煡璇㈣鍙ョ殑鎵ц淇℃伅.
2.渚?
DESC SELECT * FROM `user`
鏄剧ず:
鍏朵腑浼氭樉绀虹储寮曞拰鏌ヨ鏁版嵁璇诲彇鏁版嵁鏉℃暟绛変俊鎭?
2.1.2 浼樺寲瀛愭煡璇?/span>
鍦∕ySQL涓?灏介噺浣跨敤JOIN鏉ヤ唬鏇垮瓙鏌ヨ.鍥犱负瀛愭煡璇㈤渶瑕佸祵濂楁煡璇?宓屽鏌ヨ鏃朵細寤虹珛涓€寮犱复鏃惰〃,涓存椂琛ㄧ殑寤虹珛鍜屽垹闄ら兘浼氭湁杈冨ぇ鐨勭郴缁熷紑閿€,鑰岃繛鎺ユ煡璇笉浼氬垱寤轰复鏃惰〃,鍥犳鏁堢巼姣斿祵濂楀瓙鏌ヨ楂?
2.1.3 浣跨敤绱㈠紩
绱㈠紩鏄彁楂樻暟鎹簱鏌ヨ閫熷害鏈€閲嶈鐨勬柟娉曚箣涓€,鍏充簬绱㈠紩鍙互鍙傞珮绗旇€?/span>涓€鏂?浠嬬粛姣旇緝璇︾粏,姝ゅ璁板綍浣跨敤绱㈠紩鐨勪笁澶ф敞鎰忎簨椤?
LIKE鍏抽敭瀛楀尮閰?%'寮€澶寸殑瀛楃涓?涓嶄細浣跨敤绱㈠紩.
OR鍏抽敭瀛楃殑涓や釜瀛楁蹇呴』閮芥槸鐢ㄤ簡绱㈠紩,璇ユ煡璇㈡墠浼氫娇鐢ㄧ储寮?
浣跨敤澶氬垪绱㈠紩蹇呴』婊¤冻鏈€宸﹀尮閰?
2.1.4 鍒嗚В琛?/span>
瀵逛簬瀛楁杈冨鐨勮〃,濡傛灉鏌愪簺瀛楁浣跨敤棰戠巼杈冧綆,姝ゆ椂搴斿綋,灏嗗叾鍒嗙鍑烘潵浠庤€屽舰鎴愭柊鐨勮〃,
2.1.5 涓棿琛?/span>
瀵逛簬灏嗗ぇ閲忚繛鎺ユ煡璇㈢殑琛ㄥ彲浠ュ垱寤轰腑闂磋〃,浠庤€屽噺灏戝湪鏌ヨ鏃堕€犳垚鐨勮繛鎺ヨ€楁椂.
2.1.6 澧炲姞鍐椾綑瀛楁
绫讳技浜庡垱寤轰腑闂磋〃,澧炲姞鍐椾綑涔熸槸涓轰簡鍑忓皯杩炴帴鏌ヨ.
2.1.7 鍒嗘瀽琛?妫€鏌ヨ〃,浼樺寲琛?/span>
鍒嗘瀽琛ㄤ富瑕佹槸鍒嗘瀽琛ㄤ腑鍏抽敭瀛楃殑鍒嗗竷,妫€鏌ヨ〃涓昏鏄鏌ヨ〃涓槸鍚﹀瓨鍦ㄩ敊璇?浼樺寲琛ㄤ富瑕佹槸娑堥櫎鍒犻櫎鎴栨洿鏂伴€犳垚鐨勮〃绌洪棿娴垂.
1. 鍒嗘瀽琛? 浣跨敤 ANALYZE 鍏抽敭瀛?濡侫NALYZE TABLE user;
Op:琛ㄧず鎵ц鐨勬搷浣?
Msg_type:淇℃伅绫诲瀷,鏈塻tatus,info,note,warning,error.
Msg_text:鏄剧ず淇℃伅.
2. 妫€鏌ヨ〃: 浣跨敤 CHECK鍏抽敭瀛?濡侰HECK TABLE user [option]
option 鍙MyISAM鏈夋晥,鍏变簲涓弬鏁板€?
QUICK:涓嶆壂鎻忚,涓嶆鏌ラ敊璇殑杩炴帴.
FAST:鍙鏌ユ病鏈夋纭叧闂殑琛?
CHANGED:鍙鏌ヤ笂娆℃鏌ュ悗琚洿鏀圭殑琛ㄥ拰娌¤姝g‘鍏抽棴鐨勮〃.
MEDIUM:鎵弿琛?浠ラ獙璇佽鍒犻櫎鐨勮繛鎺ユ槸鏈夋晥鐨?涔熷彲浠ヨ绠楀悇琛屽叧閿瓧鏍¢獙鍜?
EXTENDED:鏈€鍏ㄩ潰鐨勭殑妫€鏌?瀵规瘡琛屽叧閿瓧鍏ㄩ潰鏌ユ壘.
3. 浼樺寲琛?浣跨敤OPTIMIZE鍏抽敭瀛?濡侽PTIMIZE [LOCAL|NO_WRITE_TO_BINLOG] TABLE user;
LOCAL|NO_WRITE_TO_BINLOG閮芥槸琛ㄧず涓嶅啓鍏ユ棩蹇?,浼樺寲琛ㄥ彧瀵筕ARCHAR,BLOB鍜孴EXT鏈夋晥,閫氳繃OPTIMIZE TABLE璇彞鍙互娑堥櫎鏂囦欢纰庣墖,鍦ㄦ墽琛岃繃绋嬩腑浼氬姞涓婂彧璇婚攣.
2.2 纭紭鍖?/span>
2.2.1 纭欢涓変欢濂?/span>
閰嶇疆澶氭牳蹇冨拰棰戠巼楂樼殑cpu,澶氭牳蹇冨彲浠ユ墽琛屽涓嚎绋?
閰嶇疆澶у唴瀛?鎻愰珮鍐呭瓨,鍗冲彲鎻愰珮缂撳瓨鍖哄閲?鍥犳鑳藉噺灏戠鐩業/O鏃堕棿,浠庤€屾彁楂樺搷搴旈€熷害.
閰嶇疆楂橀€熺鐩樻垨鍚堢悊鍒嗗竷纾佺洏:楂橀€熺鐩樻彁楂業/O,鍒嗗竷纾佺洏鑳芥彁楂樺苟琛屾搷浣滅殑鑳藉姏.
2.2.2 浼樺寲鏁版嵁搴撳弬鏁?/span>
浼樺寲鏁版嵁搴撳弬鏁板彲浠ユ彁楂樿祫婧愬埄鐢ㄧ巼,浠庤€屾彁楂楳ySQL鏈嶅姟鍣ㄦ€ц兘.MySQL鏈嶅姟鐨勯厤缃弬鏁伴兘鍦╩y.cnf鎴杕y.ini,涓嬮潰鍒楀嚭鎬ц兘褰卞搷杈冨ぇ鐨勫嚑涓弬鏁?
key_buffer_size:绱㈠紩缂撳啿鍖哄ぇ灏?/span>
table_cache:鑳藉悓鏃舵墦寮€琛ㄧ殑涓暟
query_cache_size鍜宷uery_cache_type:鍓嶈€呮槸鏌ヨ缂撳啿鍖哄ぇ灏?鍚庤€呮槸鍓嶉潰鍙傛暟鐨勫紑鍏?0琛ㄧず涓嶄娇鐢ㄧ紦鍐插尯,1琛ㄧず浣跨敤缂撳啿鍖?浣嗗彲浠ュ湪鏌ヨ涓娇鐢⊿QL_NO_CACHE琛ㄧず涓嶈浣跨敤缂撳啿鍖?2琛ㄧず鍦ㄦ煡璇腑鏄庣‘鎸囧嚭浣跨敤缂撳啿鍖烘墠鐢ㄧ紦鍐插尯,鍗砈QL_CACHE.
sort_buffer_size:鎺掑簭缂撳啿鍖?/span>
鏇村鍙傛暟浼犻€侀棬:
https://www.mysql.com/cn/why-mysql/performance/index.html
2.2.3 鍒嗗簱鍒嗚〃
鍥犱负鏁版嵁搴撳帇鍔涜繃澶э紝棣栧厛涓€涓棶棰樺氨鏄珮宄版湡绯荤粺鎬ц兘鍙兘浼氶檷浣庯紝鍥犱负鏁版嵁搴撹礋杞借繃楂樺鎬ц兘浼氭湁褰卞搷銆?/span>鍙﹀涓€涓紝鍘嬪姏杩囧ぇ鎶婁綘鐨勬暟鎹簱缁欐悶鎸備簡鎬庝箞鍔烇紵
鎵€浠ユ鏃朵綘蹇呴』寰楀绯荤粺鍋氬垎搴撳垎琛?+ 璇诲啓鍒嗙锛屼篃灏辨槸鎶婁竴涓簱鎷嗗垎涓哄涓簱锛岄儴缃插湪澶氫釜鏁版嵁搴撴湇鍔′笂锛岃繖鏃朵綔涓轰富搴撴壙杞藉啓鍏ヨ姹傘€?/span>鐒跺悗姣忎釜涓诲簱閮芥寕杞借嚦灏戜竴涓粠搴擄紝鐢变粠搴撴潵鎵胯浇璇昏姹傘€?/span>
2.2.4 缂撳瓨闆嗙兢
濡傛灉鐢ㄦ埛閲忚秺鏉ヨ秺澶э紝姝ゆ椂浣犲彲浠ヤ笉鍋滅殑鍔犳満鍣紝姣斿璇寸郴缁熷眰闈笉鍋滃姞鏈哄櫒锛屽氨鍙互鎵胯浇鏇撮珮鐨勫苟鍙戣姹傘€?/span>鐒跺悗鏁版嵁搴撳眰闈㈠鏋滃啓鍏ュ苟鍙戣秺鏉ヨ秺楂橈紝灏辨墿瀹瑰姞鏁版嵁搴撴湇鍔″櫒锛岄€氳繃鍒嗗簱鍒嗚〃鏄彲浠ユ敮鎸佹墿瀹规満鍣ㄧ殑锛屽鏋滄暟鎹簱灞傞潰鐨勮骞跺彂瓒婃潵瓒婇珮锛屽氨鎵╁鍔犳洿澶氱殑浠庡簱銆?/span>
浣嗘槸杩欓噷鏈変竴涓緢澶х殑闂锛?/span>鏁版嵁搴撳叾瀹炴湰韬笉鏄敤鏉ユ壙杞介珮骞跺彂璇锋眰鐨勶紝鎵€浠ラ€氬父鏉ヨ锛屾暟鎹簱鍗曟満姣忕鎵胯浇鐨勫苟鍙戝氨鍦ㄥ嚑鍗冪殑鏁伴噺绾э紝鑰屼笖鏁版嵁搴撲娇鐢ㄧ殑鏈哄櫒閮芥槸姣旇緝楂橀厤缃紝姣旇緝鏄傝吹鐨勬満鍣紝鎴愭湰寰堥珮銆?/span>濡傛灉浣犲氨鏄畝鍗曠殑涓嶅仠鐨勫姞鏈哄櫒锛屽叾瀹炴槸涓嶅鐨勩€?/span>鎵€浠?span class="mq-196">鍦ㄩ珮骞跺彂鏋舵瀯閲岄€氬父閮芥湁缂撳瓨杩欎釜鐜妭锛岀紦瀛樼郴缁熺殑璁捐灏辨槸涓轰簡鎵胯浇楂樺苟鍙戣€岀敓銆?/span>
鎵€浠ュ崟鏈烘壙杞界殑骞跺彂閲忛兘鍦ㄦ瘡绉掑嚑涓囷紝鐢氳嚦姣忕鏁板崄涓囷紝瀵归珮骞跺彂鐨勬壙杞借兘鍔涙瘮鏁版嵁搴撶郴缁熻楂樺嚭涓€鍒颁袱涓暟閲忕骇銆?/span>鎵€浠ヤ綘瀹屽叏鍙互鏍规嵁绯荤粺鐨勪笟鍔$壒鎬э紝瀵归偅绉嶅啓灏戣澶氱殑璇锋眰锛屽紩鍏ョ紦瀛橀泦缇ゃ€?/span>
鍏蜂綋鏉ヨ锛屽氨鏄?span class="mq-203">鍦ㄥ啓鏁版嵁搴撶殑鏃跺€欏悓鏃跺啓涓€浠芥暟鎹埌缂撳瓨闆嗙兢閲岋紝鐒跺悗鐢ㄧ紦瀛橀泦缇ゆ潵鎵胯浇澶ч儴鍒嗙殑璇昏姹傘€?/span>杩欐牱鐨勮瘽锛岄€氳繃缂撳瓨闆嗙兢锛屽氨鍙互鐢ㄦ洿灏戠殑鏈哄櫒璧勬簮鎵胯浇鏇撮珮鐨勫苟鍙戙€?/span>
缁撹
涓€涓畬鏁磋€屽鏉傜殑楂樺苟鍙戠郴缁熸灦鏋勪腑锛屼竴瀹氫細鍖呭惈锛?/span>鍚勭澶嶆潅鐨勮嚜鐮斿熀纭€鏋舵瀯绯荤粺銆?/span>鍚勭绮惧鐨勬灦鏋勮璁?鍥犳涓€绡囧皬鏂囬《澶氬叿鏈夋姏鐮栧紩鐜夌殑鏁堟灉,浣嗘槸鏁版嵁搴撲紭鍖栫殑鎬濇兂宸笉澶氬氨杩欎簺浜嗐€?/span>
<END>
以上是关于鏁版嵁搴撲紭鍖栫殑鎬濊矾的主要内容,如果未能解决你的问题,请参考以下文章
涓€鏉℃洿鏂癝QL鍦∕ySQL鏁版嵁搴撲腑鏄浣曟墽琛岀殑
Greenplum鏁版嵁搴撲腑绯荤粺琛╬g_class璇﹁В