缃戜笂鏈夊緢澶氱殑鏂囩珷鏁欐€庝箞閰嶇疆MySQL鏈嶅姟鍣紝浣嗚€冭檻鍒版湇鍔″櫒纭欢閰嶇疆鐨勪笉鍚岋紝鍏蜂綋搴旂敤鐨勫樊鍒紝閭d簺鏂囩珷鐨勫仛娉曞彧鑳戒綔涓哄垵姝ヨ缃弬鑰冿紝鎴戜滑闇€瑕佹牴鎹嚜宸辩殑鎯呭喌杩涜閰嶇疆浼樺寲锛屽ソ鐨勫仛娉曟槸MySQL鏈嶅姟鍣ㄧǔ瀹氳繍琛屼簡涓€娈垫椂闂村悗杩愯锛屾牴鎹湇鍔″櫒鐨勨€濈姸鎬佲€濊繘琛屼紭鍖栥€?/p>
鎵撳紑鎱㈡煡璇㈡柟娉曪細鍏跺疄鎵撳紑mysql鐨勬參鏌ヨ鏃ュ織寰堢畝鍗?鍙渶瑕佸湪mysql鐨勯厤缃枃浠堕噷(windows绯荤粺鏄痬y.ini,linux绯荤粺鏄痬y.cnf)鐨刐mysqld]涓嬮潰鍔犱笂濡備笅浠g爜锛?/p>
log-slow-queries = /usr/local/mysql/var/slowquery.log long_query_time = 1 #鍗曚綅鏄 log-queries-not-using-indexes
鎴栬€咃細
浣跨敤sql璇彞鏉ヤ慨鏀癸細涓嶈兘鎸夌収my.conf涓殑椤规潵淇敼鐨勩€備慨鏀归€氳繃"show VARIABLES like "%slow%" "
璇彞鍒楀嚭鏉ョ殑鍙橀噺锛岃繍琛屽涓媠ql锛?/p>
set global log_slow_queries = ON; set global slow_query_log = ON; #set global long_query_time=0.1; #璁剧疆澶т簬0.1s鐨剆ql璇彞璁板綍涓嬫潵锛屾垜璇曢獙娌℃湁鎴愬姛
缁撴灉锛?/p>
鎱㈡煡璇㈡棩蹇楀凡缁忓紑鍚紝濡備笅鎵€绀猴細
鏌ョ湅鎱㈡棩蹇楅厤缃儏鍐碉細
mysql> show VARIABLES like "%slow%";
+---------------------------+-------------------------------+
| Variable_name | Value |
+---------------------------+-------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/cmos1-slow.log |
+---------------------------+-------------------------------+
鏌ョ湅鎱㈡煡璇㈡椂闂达細
mysql> show variables like "long_query_time";
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.01 sec)
瓒呰繃10绉掔殑鏌ヨ灏嗕細琚褰曪紝娴嬭瘯濡備笅:
鎵句釜瀹㈡埛绔墽琛宻elect sleep(11);
鍐嶇湅show status鍙婃棩蹇楋細
mysql> show processlist; +----+------+---------------------+---------+---------+------+------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+---------------------+---------+---------+------+------------+------------------+ | 3 | root | 10.202.37.75:54830 | ud_omcs | Sleep | 3 | | NULL | | 4 | root | 10.202.11.118:16644 | ud_omcs | Sleep | 0 | | NULL | | 7 | root | localhost | ud_omcs | Query | 0 | starting | show processlist | | 8 | root | 10.118.62.181:51533 | ud_omcs | Sleep | 1328 | | NULL | | 9 | root | 10.118.62.181:51551 | ud_omcs | Query | 9 | User sleep | select sleep(11) | | 10 | root | 10.118.62.156:52938 | omcs | Sleep | 0 | | NULL | | 11 | root | 10.118.62.156:52939 | omcs | Sleep | 0 | | NULL | +----+------+---------------------+---------+---------+------+------------+------------------+
mysql> show global status like 鈥?/span>%slow%鈥?/span>; +---------------------+-------+ | Variable_name | Value | +---------------------+-------+ | Slow_launch_threads | 0 | | Slow_queries | 1 | +---------------------+-------+ 2 rows in set (0.00 sec)
##select db, query_TIME, lock_time, rows_examined, sql_text from mysql.slow_log select db, query_TIME, lock_time, rows_examined, sql_text from mysql.slow_log
鎱㈡棩蹇楀涓嬶細
鍒嗘瀽瀹屼簡璁板緱鍏抽棴鎱㈡棩蹇椼€?/span>
鎵ц锛?/p>
set global log_slow_queries = OFF; set global slow_query_log = OFF;
缁撴灉锛?/p>
mysql> show VARIABLES like "%slow%";
+---------------------------+-------------------------------+
| Variable_name | Value |
+---------------------------+-------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /var/lib/mysql/cmos1-slow.log |
+---------------------------+-------------------------------+
5 rows in set (0.00 sec)
閰嶇疆涓墦寮€浜嗚褰曟參鏌ヨ锛屾墽琛屾椂闂磋秴杩?绉掔殑鍗充负鎱㈡煡璇紝绯荤粺鏄剧ず鏈?148涓參鏌ヨ锛屼綘鍙互鍒嗘瀽鎱㈡煡璇㈡棩蹇楋紝鎵惧嚭鏈夐棶棰樼殑SQL璇彞锛屾參鏌ヨ鏃堕棿涓嶅疁璁剧疆杩囬暱锛屽惁鍒欐剰涔変笉澶э紝鏈€濂藉湪5绉掍互鍐咃紝濡傛灉浣犻渶瑕佸井绉掔骇鍒殑鎱㈡煡璇紝鍙互鑰冭檻缁?/span>MySQL鎵撹ˉ涓侊細http://www.percona.com/docs/wiki/release:start锛岃寰楁壘瀵瑰簲鐨勭増鏈€?/span>
銆€銆€mysql> show global status;
銆€銆€鍙互鍒楀嚭MySQL鏈嶅姟鍣ㄨ繍琛屽悇绉嶇姸鎬佸€硷紝鍙﹀锛屾煡璇ySQL鏈嶅姟鍣ㄩ厤缃俊鎭鍙ワ細
銆€銆€mysql> show variables;
銆€銆€涓€銆佹參鏌ヨ
銆€銆€mysql> show variables like 鈥?slow%鈥?
銆€銆€+------------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+------------------+-------+
銆€銆€| log_slow_queries | ON |
銆€銆€| slow_launch_time | 2 |
銆€銆€+------------------+-------+
銆€銆€mysql> show global status like 鈥?slow%鈥?
銆€銆€+---------------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+---------------------+-------+
銆€銆€| Slow_launch_threads | 0 |
銆€銆€| Slow_queries | 4148 |
銆€銆€+---------------------+-------+銆€銆€
銆€銆€鎵撳紑鎱㈡煡璇㈡棩蹇楀彲鑳戒細瀵圭郴缁熸€ц兘鏈変竴鐐圭偣褰卞搷锛屽鏋滀綘鐨凪ySQL鏄富-浠庣粨鏋勶紝鍙互鑰冭檻鎵撳紑鍏朵腑涓€鍙颁粠鏈嶅姟鍣ㄧ殑鎱㈡煡璇㈡棩蹇楋紝杩欐牱鏃㈠彲浠ョ洃鎺ф參鏌ヨ锛屽绯荤粺鎬ц兘褰卞搷鍙堝皬銆?/p>
銆€銆€浜屻€佽繛鎺ユ暟
銆€銆€缁忓父浼氶亣瑙佲€滿ySQL: ERROR 1040: Too many connections鈥濈殑鎯呭喌锛屼竴绉嶆槸璁块棶閲忕‘瀹炲緢楂橈紝MySQL鏈嶅姟鍣ㄦ姉涓嶄綇锛岃繖涓椂鍊欏氨瑕佽€冭檻澧炲姞浠庢湇鍔″櫒鍒嗘暎璇诲帇鍔涳紝鍙﹀涓€绉嶆儏鍐垫槸MySQL閰嶇疆鏂囦欢涓璵ax_connections鍊艰繃灏忥細
銆€銆€mysql> show variables like 鈥榤ax_connections鈥?
銆€銆€+-----------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+-----------------+-------+
銆€銆€| max_connections | 256 |
銆€銆€+-----------------+-------+銆€銆€
杩欏彴MySQL鏈嶅姟鍣ㄦ渶澶ц繛鎺ユ暟鏄?56锛岀劧鍚庢煡璇竴涓嬫湇鍔″櫒鍝嶅簲鐨勬渶澶ц繛鎺ユ暟锛?nbsp;
銆€銆€mysql> show global status like 鈥楳ax_used_connections鈥?
銆€銆€MySQL鏈嶅姟鍣ㄨ繃鍘荤殑鏈€澶ц繛鎺ユ暟鏄?45锛屾病鏈夎揪鍒版湇鍔″櫒杩炴帴鏁颁笂闄?56锛屽簲璇ユ病鏈夊嚭鐜?040閿欒锛屾瘮杈冪悊鎯崇殑璁剧疆鏄細
銆€銆€Max_used_connections / max_connections * 100% 鈮?85%
銆€銆€鏈€澶ц繛鎺ユ暟鍗犱笂闄愯繛鎺ユ暟鐨?5%宸﹀彸锛屽鏋滃彂鐜版瘮渚嬪湪10%浠ヤ笅锛孧ySQL鏈嶅姟鍣ㄨ繛鎺ユ暟涓婇檺璁剧疆鐨勮繃楂樹簡銆?/p>
銆€銆€涓夈€並ey_buffer_size
銆€銆€key_buffer_size鏄MyISAM琛ㄦ€ц兘褰卞搷鏈€澶х殑涓€涓弬鏁帮紝涓嬮潰涓€鍙颁互MyISAM涓轰富瑕佸瓨鍌ㄥ紩鎿庢湇鍔″櫒鐨勯厤缃細
銆€銆€mysql> show variables like 鈥榢ey_buffer_size鈥?
銆€銆€+-----------------+------------+
銆€銆€| Variable_name | Value |
銆€銆€+-----------------+------------+
銆€銆€| key_buffer_size | 536870912 |
銆€銆€+-----------------+------------+銆€銆€
鍒嗛厤浜?12MB鍐呭瓨缁檏ey_buffer_size锛屾垜浠啀鐪嬩竴涓媖ey_buffer_size鐨勪娇鐢ㄦ儏鍐碉細
銆€銆€mysql> show global status like 鈥榢ey_read%鈥?
銆€銆€+------------------------+-------------+
銆€銆€| Variable_name | Value | mysql
銆€銆€+------------------------+-------------+
銆€銆€| Key_read_requests | 27813678764 |
銆€銆€| Key_reads | 6798830 |
銆€銆€+------------------------+-------------+銆€銆€
涓€鍏辨湁27813678764涓储寮曡鍙栬姹傦紝鏈?798830涓姹傚湪鍐呭瓨涓病鏈夋壘鍒扮洿鎺ヤ粠纭洏璇诲彇绱㈠紩锛岃绠楃储寮曟湭鍛戒腑缂撳瓨鐨勬鐜囷細
銆€銆€key_cache_miss_rate = Key_reads / Key_read_requests * 100%
銆€銆€姣斿涓婇潰鐨勬暟鎹紝key_cache_miss_rate涓?.0244%锛?000涓储寮曡鍙栬姹傛墠鏈変竴涓洿鎺ヨ纭洏锛屽凡缁忓緢BT浜?key_cache_miss_rate鍦?.1%浠ヤ笅閮藉緢濂?姣?000涓姹傛湁涓€涓洿鎺ヨ纭洏)锛屽鏋渒ey_cache_miss_rate鍦?.01%浠ヤ笅鐨勮瘽锛宬ey_buffer_size鍒嗛厤鐨勮繃澶氾紝鍙互閫傚綋鍑忓皯銆?br>銆€銆€MySQL鏈嶅姟鍣ㄨ繕鎻愪緵浜唊ey_blocks_*鍙傛暟锛?nbsp;
銆€銆€mysql> show global status like 鈥榢ey_blocks_u%鈥?
銆€銆€+------------------------+-------------+
銆€銆€| Variable_name | Value |
銆€銆€+------------------------+-------------+
銆€銆€| Key_blocks_unused | 0 |
銆€銆€| Key_blocks_used | 413543 |
銆€銆€+------------------------+-------------+銆€銆€
Key_blocks_unused琛ㄧず鏈娇鐢ㄧ殑缂撳瓨绨?blocks)鏁帮紝Key_blocks_used琛ㄧず鏇剧粡鐢ㄥ埌鐨勬渶澶х殑blocks鏁帮紝姣斿杩欏彴鏈嶅姟鍣紝鎵€鏈夌殑缂撳瓨閮界敤鍒颁簡锛岃涔堝鍔爇ey_buffer_size锛岃涔堝氨鏄繃娓$储寮曚簡锛屾妸缂撳瓨鍗犳弧浜嗐€傛瘮杈冪悊鎯崇殑璁剧疆锛?nbsp;
銆€銆€Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% 鈮?80%
銆€銆€鍥涖€佷复鏃惰〃
銆€銆€mysql> show global status like 鈥榗reated_tmp%鈥?
銆€銆€+-------------------------+---------+
銆€銆€| Variable_name | Value |
銆€銆€+-------------------------+---------+
銆€銆€| Created_tmp_disk_tables | 21197 |
銆€銆€| Created_tmp_files | 58 |
銆€銆€| Created_tmp_tables | 1771587 |
銆€銆€+-------------------------+---------+銆€銆€
姣忔鍒涘缓涓存椂琛紝Created_tmp_tables澧炲姞锛屽鏋滄槸鍦ㄧ鐩樹笂鍒涘缓涓存椂琛紝Created_tmp_disk_tables涔熷鍔?Created_tmp_files琛ㄧずMySQL鏈嶅姟鍒涘缓鐨勪复鏃舵枃浠舵枃浠舵暟锛屾瘮杈冪悊鎯崇殑閰嶇疆鏄細
銆€銆€Created_tmp_disk_tables / Created_tmp_tables * 100% <= 25%
銆€銆€姣斿涓婇潰鐨勬湇鍔″櫒Created_tmp_disk_tables / Created_tmp_tables * 100% = 1.20%锛屽簲璇ョ浉褰撳ソ浜嗐€傛垜浠啀鐪嬩竴涓婱ySQL鏈嶅姟鍣ㄥ涓存椂琛ㄧ殑閰嶇疆锛?nbsp;
銆€銆€mysql> show variables where Variable_name in (鈥榯mp_table_size鈥? 鈥榤ax_heap_table_size鈥?;
銆€銆€+---------------------+-----------+
銆€銆€| Variable_name | Value |
銆€銆€+---------------------+-----------+
銆€銆€| max_heap_table_size | 268435456 |
銆€銆€| tmp_table_size | 536870912 |
銆€銆€+---------------------+-----------+銆€銆€
鍙湁256MB浠ヤ笅鐨勪复鏃惰〃鎵嶈兘鍏ㄩ儴鏀惧唴瀛橈紝瓒呰繃鐨勫氨浼氱敤鍒扮‖鐩樹复鏃惰〃銆?br>銆€銆€浜斻€丱pen Table鎯呭喌
銆€銆€mysql> show global status like 鈥榦pen%tables%鈥?
銆€銆€+---------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+---------------+-------+
銆€銆€| Open_tables | 919 |
銆€銆€| Opened_tables | 1951 |
銆€銆€+---------------+-------+銆€銆€
Open_tables琛ㄧず鎵撳紑琛ㄧ殑鏁伴噺锛孫pened_tables琛ㄧず鎵撳紑杩囩殑琛ㄦ暟閲忥紝濡傛灉Opened_tables鏁伴噺杩囧ぇ锛岃鏄庨厤缃腑table_cache(5.1.3涔嬪悗杩欎釜鍊煎彨鍋歵able_open_cache)鍊煎彲鑳藉お灏忥紝鎴戜滑鏌ヨ涓€涓嬫湇鍔″櫒table_cache鍊硷細
銆€銆€mysql> show variables like 鈥榯able_cache鈥?
銆€銆€+---------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+---------------+-------+
銆€銆€| table_cache | 2048 |
銆€銆€+---------------+-------+
銆€銆€姣旇緝鍚堥€傜殑鍊间负锛?nbsp;
銆€銆€Open_tables / Opened_tables * 100% >= 85%
銆€銆€Open_tables / table_cache * 100% <= 95%
銆€銆€鍏€佽繘绋嬩娇鐢ㄦ儏鍐?br>銆€銆€mysql> show global status like 鈥楾hread%鈥?
銆€銆€+-------------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+-------------------+-------+
銆€銆€| Threads_cached | 46 |
銆€銆€| Threads_connected | 2 |
銆€銆€| Threads_created | 570 |
銆€銆€| Threads_running | 1 |
銆€銆€+-------------------+-------+銆€銆€
濡傛灉鎴戜滑鍦∕ySQL鏈嶅姟鍣ㄩ厤缃枃浠朵腑璁剧疆浜唗hread_cache_size锛屽綋瀹㈡埛绔柇寮€涔嬪悗锛屾湇鍔″櫒澶勭悊姝ゅ鎴风殑绾跨▼灏嗕細缂撳瓨璧锋潵浠ュ搷搴斾笅涓€涓鎴疯€屼笉鏄攢姣?鍓嶆彁鏄紦瀛樻暟鏈揪涓婇檺)銆俆hreads_created琛ㄧず鍒涘缓杩囩殑绾跨▼鏁帮紝濡傛灉鍙戠幇Threads_created鍊艰繃澶х殑璇濓紝琛ㄦ槑MySQL鏈嶅姟鍣ㄤ竴鐩村湪鍒涘缓绾跨▼锛岃繖涔熸槸姣旇緝鑰楄祫婧愶紝鍙互閫傚綋澧炲姞閰嶇疆鏂囦欢涓璽hread_cache_size鍊硷紝鏌ヨ鏈嶅姟鍣╰hread_cache_size閰嶇疆锛?nbsp;
銆€銆€mysql> show variables like 鈥榯hread_cache_size鈥?
銆€銆€+-------------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+-------------------+-------+
銆€銆€| thread_cache_size | 64 |
銆€銆€+-------------------+-------+銆€銆€
绀轰緥涓殑鏈嶅姟鍣ㄨ繕鏄尯鍋ュ悍鐨勩€?/p>
銆€銆€涓冦€佹煡璇㈢紦瀛?query cache)
銆€銆€mysql> show global status like 鈥榪cache%鈥?
銆€銆€+-------------------------+-----------+
銆€銆€| Variable_name | Value |
銆€銆€+-------------------------+-----------+
銆€銆€| Qcache_free_blocks | 22756 |
銆€銆€| Qcache_free_memory | 76764704 |
銆€銆€| Qcache_hits | 213028692 |
銆€銆€| Qcache_inserts | 208894227 |
銆€銆€| Qcache_lowmem_prunes | 4010916 |
銆€銆€| Qcache_not_cached | 13385031 |
銆€銆€| Qcache_queries_in_cache | 43560 |
銆€銆€| Qcache_total_blocks | 111212 |
銆€銆€+-------------------------+-----------+銆€銆€
MySQL鏌ヨ缂撳瓨鍙橀噺瑙i噴锛?br>銆€銆€Qcache_free_blocks锛氱紦瀛樹腑鐩搁偦鍐呭瓨鍧楃殑涓暟銆傛暟鐩ぇ璇存槑鍙兘鏈夌鐗囥€侳LUSH QUERY CACHE浼氬缂撳瓨涓殑纰庣墖杩涜鏁寸悊锛屼粠鑰屽緱鍒颁竴涓┖闂插潡銆?br>銆€銆€Qcache_free_memory锛氱紦瀛樹腑鐨勭┖闂插唴瀛樸€?nbsp;
銆€銆€Qcache_hits锛氭瘡娆℃煡璇㈠湪缂撳瓨涓懡涓椂灏卞澶?br>銆€銆€Qcache_inserts锛氭瘡娆℃彃鍏ヤ竴涓煡璇㈡椂灏卞澶с€傚懡涓鏁伴櫎浠ユ彃鍏ユ鏁板氨鏄笉涓瘮鐜囥€?br>銆€銆€Qcache_lowmem_prunes锛氱紦瀛樺嚭鐜板唴瀛樹笉瓒冲苟涓斿繀椤昏杩涜娓呯悊浠ヤ究涓烘洿澶氭煡璇㈡彁渚涚┖闂寸殑娆℃暟銆傝繖涓暟瀛楁渶濂介暱鏃堕棿鏉ョ湅;濡傛灉杩欎釜鏁板瓧鍦ㄤ笉鏂闀匡紝灏辫〃绀哄彲鑳界鐗囬潪甯镐弗閲嶏紝鎴栬€呭唴瀛樺緢灏戙€?涓婇潰鐨?free_blocks鍜宖ree_memory鍙互鍛婅瘔鎮ㄥ睘浜庡摢绉嶆儏鍐?
銆€銆€Qcache_not_cached锛氫笉閫傚悎杩涜缂撳瓨鐨勬煡璇㈢殑鏁伴噺锛岄€氬父鏄敱浜庤繖浜涙煡璇笉鏄?SELECT 璇彞鎴栬€呯敤浜唍ow()涔嬬被鐨勫嚱鏁般€?br>銆€銆€Qcache_queries_in_cache锛氬綋鍓嶇紦瀛樼殑鏌ヨ(鍜屽搷搴?鐨勬暟閲忋€?br>銆€銆€Qcache_total_blocks锛氱紦瀛樹腑鍧楃殑鏁伴噺銆?br>銆€銆€鎴戜滑鍐嶆煡璇竴涓嬫湇鍔″櫒鍏充簬query_cache鐨勯厤缃細
銆€銆€mysql> show variables like 鈥榪uery_cache%鈥?
銆€銆€+------------------------------+-----------+
銆€銆€| Variable_name | Value |
銆€銆€+------------------------------+-----------+
銆€銆€| query_cache_limit | 2097152 |
銆€銆€| query_cache_min_res_unit | 4096 |
銆€銆€| query_cache_size | 203423744 |
銆€銆€| query_cache_type | ON |
銆€銆€| query_cache_wlock_invalidate | OFF |
+鈥斺€斺€斺€斺€斺€斺€斺€斺€斺€?鈥斺€斺€斺€?
銆€銆€鍚勫瓧娈电殑瑙i噴锛?br>銆€銆€query_cache_limit锛氳秴杩囨澶у皬鐨勬煡璇㈠皢涓嶇紦瀛?br>銆€銆€query_cache_min_res_unit锛氱紦瀛樺潡鐨勬渶灏忓ぇ灏?br>銆€銆€query_cache_size锛氭煡璇㈢紦瀛樺ぇ灏?br>銆€銆€query_cache_type锛氱紦瀛樼被鍨嬶紝鍐冲畾缂撳瓨浠€涔堟牱鐨勬煡璇紝绀轰緥涓〃绀轰笉缂撳瓨 select sql_no_cache 鏌ヨ
銆€銆€query_cache_wlock_invalidate锛氬綋鏈夊叾浠栧鎴风姝e湪瀵筂yISAM琛ㄨ繘琛屽啓鎿嶄綔鏃讹紝濡傛灉鏌ヨ鍦╭uery cache涓紝鏄惁杩斿洖cache缁撴灉杩樻槸绛夊啓鎿嶄綔瀹屾垚鍐嶈琛ㄨ幏鍙栫粨鏋溿€?br>銆€銆€query_cache_min_res_unit鐨勯厤缃槸涓€鏌勨€濆弻鍒冨墤鈥濓紝榛樿鏄?KB锛岃缃€煎ぇ瀵?a class="replace_word" title="Apache Spark鐭ヨ瘑搴? href="http://lib.csdn.net/base/spark" target="_blank">澶ф暟鎹?/a>鏌ヨ鏈夊ソ澶勶紝浣嗗鏋滀綘鐨勬煡璇㈤兘鏄皬鏁版嵁鏌ヨ锛屽氨瀹规槗閫犳垚鍐呭瓨纰庣墖鍜屾氮璐广€?br>銆€銆€鏌ヨ缂撳瓨纰庣墖鐜?= Qcache_free_blocks / Qcache_total_blocks * 100%
銆€銆€濡傛灉鏌ヨ缂撳瓨纰庣墖鐜囪秴杩?0%锛屽彲浠ョ敤FLUSH QUERY CACHE鏁寸悊缂撳瓨纰庣墖锛屾垨鑰呰瘯璇曞噺灏弎uery_cache_min_res_unit锛屽鏋滀綘鐨勬煡璇㈤兘鏄皬鏁版嵁閲忕殑璇濄€?br>銆€銆€鏌ヨ缂撳瓨鍒╃敤鐜?= (query_cache_size - Qcache_free_memory) / query_cache_size * 100%
銆€銆€鏌ヨ缂撳瓨鍒╃敤鐜囧湪25%浠ヤ笅鐨勮瘽璇存槑query_cache_size璁剧疆鐨勮繃澶э紝鍙€傚綋鍑忓皬;鏌ヨ缂撳瓨鍒╃敤鐜囧湪80%浠ヤ笂鑰屼笖Qcache_lowmem_prunes > 50鐨勮瘽璇存槑query_cache_size鍙兘鏈夌偣灏忥紝瑕佷笉灏辨槸纰庣墖澶銆?nbsp;
銆€銆€鏌ヨ缂撳瓨鍛戒腑鐜?= (Qcache_hits - Qcache_inserts) / Qcache_hits * 100%
銆€銆€绀轰緥鏈嶅姟鍣?鏌ヨ缂撳瓨纰庣墖鐜?= 20.46%锛屾煡璇㈢紦瀛樺埄鐢ㄧ巼 = 62.26%锛屾煡璇㈢紦瀛樺懡涓巼 = 1.94%锛屽懡涓巼寰堝樊锛屽彲鑳藉啓鎿嶄綔姣旇緝棰戠箒鍚э紝鑰屼笖鍙兘鏈変簺纰庣墖銆?/p>
銆€銆€鍏€佹帓搴忎娇鐢ㄦ儏鍐?nbsp;
銆€銆€mysql> show global status like 鈥榮ort%鈥?
銆€銆€+-------------------+------------+
銆€銆€| Variable_name | Value |
銆€銆€+-------------------+------------+
銆€銆€| Sort_merge_passes | 29 |
銆€銆€| Sort_range | 37432840 |
銆€銆€| Sort_rows | 9178691532 |
銆€銆€| Sort_scan | 1860569 |
銆€銆€+-------------------+------------+銆€銆€
Sort_merge_passes 鍖呮嫭涓ゆ銆侻ySQL 棣栧厛浼氬皾璇曞湪鍐呭瓨涓仛鎺掑簭锛屼娇鐢ㄧ殑鍐呭瓨澶у皬鐢辩郴缁熷彉閲?Sort_buffer_size 鍐冲畾锛屽鏋滃畠鐨勫ぇ灏忎笉澶熸妸鎵€鏈夌殑璁板綍閮借鍒板唴瀛樹腑锛孧ySQL 灏变細鎶婃瘡娆″湪鍐呭瓨涓帓搴忕殑缁撴灉瀛樺埌涓存椂鏂囦欢涓紝绛?MySQL 鎵惧埌鎵€鏈夎褰曚箣鍚庯紝鍐嶆妸涓存椂鏂囦欢涓殑璁板綍鍋氫竴娆℃帓搴忋€傝繖鍐嶆鎺掑簭灏变細澧炲姞 Sort_merge_passes銆傚疄闄呬笂锛孧ySQL 浼氱敤鍙︿竴涓复鏃舵枃浠舵潵瀛樺啀娆℃帓搴忕殑缁撴灉锛屾墍浠ラ€氬父浼氱湅鍒?Sort_merge_passes 澧炲姞鐨勬暟鍊兼槸寤轰复鏃舵枃浠舵暟鐨勪袱鍊嶃€傚洜涓虹敤鍒颁簡涓存椂鏂囦欢锛屾墍浠ラ€熷害鍙兘浼氭瘮杈冩參锛屽鍔?Sort_buffer_size 浼氬噺灏?Sort_merge_passes 鍜?鍒涘缓涓存椂鏂囦欢鐨勬鏁般€備絾鐩茬洰鐨勫鍔?Sort_buffer_size 骞朵笉涓€瀹氳兘鎻愰珮閫熷害锛岃 How fast can you sort data with MySQL?(寮曡嚜http://qroom.blogspot.com/2007/09/mysql-select-sort.html锛岃矊浼艰澧? mysql
銆€銆€鍙﹀锛屽鍔爎ead_rnd_buffer_size(3.2.3鏄痳ecord_rnd_buffer_size)鐨勫€煎鎺掑簭鐨勬搷浣滀篃鏈変竴鐐圭殑濂藉锛屽弬瑙侊細http://www.mysqlperformanceblog.com/2007/07/24/what-exactly-is-read_rnd_buffer_size/
銆€銆€涔濄€佹枃浠舵墦寮€鏁?open_files)
銆€銆€mysql> show global status like 鈥榦pen_files鈥?
銆€銆€+---------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+---------------+-------+
銆€銆€| Open_files | 1410 |
銆€銆€+---------------+-------+
銆€銆€mysql> show variables like 鈥榦pen_files_limit鈥?
銆€銆€+------------------+-------+
銆€銆€| Variable_name | Value |
銆€銆€+------------------+-------+
銆€銆€| open_files_limit | 4590 |
銆€銆€+------------------+-------+銆€銆€
姣旇緝鍚堥€傜殑璁剧疆锛歄pen_files / open_files_limit * 100% <= 75%
銆€銆€鍗併€佽〃閿佹儏鍐?nbsp;
銆€銆€mysql> show global status like 鈥榯able_locks%鈥?
銆€銆€+-----------------------+-----------+
銆€銆€| Variable_name | Value |
銆€銆€+-----------------------+-----------+
銆€銆€| Table_locks_immediate | 490206328 |
銆€銆€| Table_locks_waited | 2084912 |
銆€銆€+-----------------------+-----------+銆€銆€
Table_locks_immediate琛ㄧず绔嬪嵆閲婃斁琛ㄩ攣鏁帮紝Table_locks_waited琛ㄧず闇€瑕佺瓑寰呯殑琛ㄩ攣鏁帮紝濡傛灉Table_locks_immediate / Table_locks_waited > 5000锛屾渶濂介噰鐢↖nnoDB寮曟搸锛屽洜涓篒nnoDB鏄閿佽€孧yISAM鏄〃閿侊紝瀵逛簬楂樺苟鍙戝啓鍏ョ殑搴旂敤InnoDB鏁堟灉浼氬ソ浜涖€傜ず渚嬩腑鐨勬湇鍔″櫒Table_locks_immediate / Table_locks_waited = 235锛孧yISAM灏辫冻澶熶簡銆?/p>
銆€銆€鍗佷竴銆佽〃鎵弿鎯呭喌
銆€銆€mysql> show global status like 鈥榟andler_read%鈥?
銆€銆€+-----------------------+-------------+
銆€銆€| Variable_name | Value |
銆€銆€+-----------------------+-------------+
銆€銆€| Handler_read_first | 5803750 |
銆€銆€| Handler_read_key | 6049319850 |
銆€銆€| Handler_read_next | 94440908210 |
銆€銆€| Handler_read_prev | 34822001724 |
銆€銆€| Handler_read_rnd | 405482605 |
銆€銆€| Handler_read_rnd_next | 18912877839 |
銆€銆€+-----------------------+-------------+銆€銆€
鍚勫瓧娈佃В閲婂弬瑙?a href="http://hi.baidu.com/thinkinginlamp/blog/item/31690cd7c4bc5cdaa144df9c.html" rel="nofollow">http://hi.baidu.com/thinkinginlamp/blog/item/31690cd7c4bc5cdaa144df9c.html锛岃皟鍑烘湇鍔″櫒瀹屾垚鐨勬煡璇㈣姹傛鏁帮細
銆€銆€mysql> show global status like 鈥榗om_select鈥?
銆€銆€+---------------+-----------+
銆€銆€| Variable_name | Value |
銆€銆€+---------------+-----------+
銆€銆€| Com_select | 222693559 |
銆€銆€+---------------+-----------+銆€銆€
璁$畻琛ㄦ壂鎻忕巼锛?br>銆€銆€琛ㄦ壂鎻忕巼 = Handler_read_rnd_next / Com_select
銆€銆€濡傛灉琛ㄦ壂鎻忕巼瓒呰繃4000锛岃鏄庤繘琛屼簡澶琛ㄦ壂鎻忥紝寰堟湁鍙兘绱㈠紩娌℃湁寤哄ソ锛屽鍔爎ead_buffer_size鍊间細鏈変竴浜涘ソ澶勶紝浣嗘渶濂戒笉瑕佽秴杩?MB銆?br>銆€銆€鍚庤锛?nbsp;
銆€銆€鏂囦腑鎻愬埌涓€浜涙暟瀛楅兘鏄弬鑰冨€硷紝浜嗚В鍩烘湰鍘熺悊灏卞彲浠ワ紝闄や簡MySQL鎻愪緵鐨勫悇绉峴tatus鍊煎锛?a class="replace_word" title="鎿嶄綔绯荤粺鐭ヨ瘑搴? href="http://lib.csdn.net/base/operatingsystem" target="_blank">鎿嶄綔绯荤粺鐨勪竴浜涙€ц兘鎸囨爣涔熷緢閲嶈锛屾瘮濡傚父鐢ㄧ殑top,iostat绛夛紝灏ゅ叾鏄痠ostat锛岀幇鍦ㄧ殑绯荤粺鐡堕涓€鑸兘鍦ㄧ鐩業O涓婏紝鍏充簬iostat鐨勪娇鐢?