{"id":1309,"date":"2012-02-24T09:29:52","date_gmt":"2012-02-24T01:29:52","guid":{"rendered":"http:\/\/doophp.sinaapp.com\/?p=1309"},"modified":"2012-03-12T10:48:27","modified_gmt":"2012-03-12T02:48:27","slug":"mysql-performance-params-reference","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/mysql\/mysql-performance-params-reference.html","title":{"rendered":"MySQL\u6027\u80fd\u4f18\u5316\u53c2\u6570\u6574\u7406(\u9646\u7eed\u66f4\u65b0)"},"content":{"rendered":"
\u672c\u6587\u5c31\u5e38\u89c1MySQL\u8fd0\u884c\u53c2\u6570\u505a\u8be6\u7ec6\u5217\u4e3e\u4e0e\u8bf4\u660e\uff0c\u5e76\u5bf9\u5404\u53c2\u6570\u7684\u8bbe\u7f6e\u6761\u4ef6\u505a\u5c3d\u53ef\u80fd\u8be6\u5c3d\u7684\u89e3\u91ca\uff0c\u7531\u4e8eMySQL\u914d\u7f6e\u53c2\u6570\u6bd4\u8f83\u591a\uff0c\u672c\u6587\u5c3d\u53ef\u80fd\u5168\u9762\u4ecb\u7ecd\u5404\u53c2\u6570\uff0c\u5982\u6709\u9057\u6f0f\u5c06\u9646\u7eed\u66f4\u65b0\uff0c\u6b22\u8fce\u5927\u5bb6\u70b9\u8bc4\u6295\u7a3f.<\/p>\n
\u9274\u4e8eMySQL\u914d\u7f6e\u53c2\u6570\u4f18\u5316\u4e0e\u6570\u636e\u5e93\u8fd0\u884c\u73af\u5883\u6709\u5bc6\u5207\u5173\u8054\uff0c\u672c\u6587\u4e3b\u8981\u5bf9MySQL\u53c2\u6570\u505a\u89e3\u91ca\u7ffb\u8bd1\u6574\u7406\uff0c\u90e8\u5206\u8bbe\u7f6e\u53c2\u6570\u503c\u6765\u6e90\u6574\u7406\u81ea\u5176\u4ed6\u535a\u5ba2\uff0c\u8003\u8651\u5230\u5c0a\u91cd\u539f\u521b\uff0c\u672c\u4eba\u5c3d\u91cf\u6807\u6ce8\u5f15\u7528\u6765\u6e90\uff0c\u5982\u6709\u9057\u6f0f\uff0c\u8bf7\u53ca\u65f6\u8054\u7cfb\u6211\u66f4\u6b63\u3002<\/p>\n
\n\n
- 0(OFF)\uff1a\u5173\u95ed Query Cache \u529f\u80fd\uff0c\u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u4e0d\u4f1a\u4f7f\u7528 Query Cache<\/li>\n
- 1(ON)\uff1a\u5f00\u542f Query Cache \u529f\u80fd\uff0c\u4f46\u662f\u5f53 SELECT \u8bed\u53e5\u4e2d\u4f7f\u7528\u7684 SQL_NO_CACHE \u63d0\u793a\u540e\uff0c\u5c06\u4e0d\u4f7f\u7528Query Cache<\/li>\n
- 2(DEMAND)\uff1a\u5f00\u542f Query Cache \u529f\u80fd\uff0c\u4f46\u662f\u53ea\u6709\u5f53 SELECT \u8bed\u53e5\u4e2d\u4f7f\u7528\u4e86 SQL_CACHE \u63d0\u793a\u540e\uff0c\u624d\u4f7f\u7528 Query Cache
\nquery_cache_type > 0 \u65f6(\u53d8\u91cfhave_query_cache=YES)\uff0c\u5982\u679cquery_cache_size=0(\u9ed8\u8ba4\u503c\u4e3a0)\uff0cQuery\u4e5f\u4e0d\u53ef\u7528<\/em><\/li>\n<\/ul>\n<\/blockquote>\n<\/li>\n- query_cache_size\uff1a<\/strong>\u8bbe\u7f6e Query Cache \u6240\u4f7f\u7528\u7684\u5185\u5b58\u5927\u5c0f\uff0c\u9ed8\u8ba4\u503c\u4e3a0\uff0c\u5927\u5c0f\u5fc5\u987b\u662f1024\u7684\u6574\u6570\u500d<\/span>\uff0c\u5982\u679c\u4e0d\u662f\u6574\u6570\u500d\uff0cMySQL \u4f1a\u81ea\u52a8\u8c03\u6574\u964d\u4f4e\u6700\u5c0f\u91cf\u4ee5\u8fbe\u52301024\u7684\u500d\u6570\u3002query_cache_size\u6700\u5c0f\u503c\u4e0d\u80fd\u5c0f\u4e8e40KB\uff0c\u5426\u5219\u7cfb\u7edf\u5c06\u4f1a\u4ea7\u751f\u4e00\u4e2aWARNING:Query cache failed to set size 39936;new query cache size is 0.<\/em><\/li>\n
- query_cache_limit\uff1a<\/strong>\u5141\u8bb8 Cache \u7684\u5355\u6761 Query \u7ed3\u679c\u96c6\u7684\u6700\u5927\u5bb9\u91cf\uff0c\u9ed8\u8ba4\u662f1MB\uff0c\u8d85\u8fc7\u6b64\u53c2\u6570\u8bbe\u7f6e\u7684 Query \u7ed3\u679c\u96c6\u5c06\u4e0d\u4f1a\u88ab Cache.<\/li>\n
- query_cache_min_res_unit\uff1a<\/strong>\u8bbe\u7f6e Query Cache \u4e2d\u6bcf\u6b21\u5206\u914d\u5185\u5b58\u7684\u6700\u5c0f\u7a7a\u95f4\u5927\u5c0f\uff0c\u4e5f\u5c31\u662f\u6bcf\u4e2a Query \u7684 Cache \u6700\u5c0f\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u5927\u5c0f.<\/li>\n
- query_cache_wlock_invalidate\uff1a<\/strong>\u63a7\u5236\u5f53\u6709\u5199\u9501\u5b9a\u53d1\u751f\u5728\u8868\u4e0a\u7684\u65f6\u523b\u662f\u5426\u5148\u5931\u6548\u8be5\u8868\u76f8\u5173\u7684 Query Cache\uff0c\u5982\u679c\u8bbe\u7f6e\u4e3a 1(TRUE)\uff0c\u5219\u5728\u5199\u9501\u5b9a\u7684\u540c\u65f6\u5c06\u5931\u6548\u8be5\u8868\u76f8\u5173\u7684\u6240\u6709 Query Cache\uff0c\u5982\u679c\u8bbe\u7f6e\u4e3a0(FALSE)\u5219\u5728\u9501\u5b9a\u65f6\u523b\u4ecd\u7136\u5141\u8bb8\u8bfb\u53d6\u8be5\u8868\u76f8\u5173\u7684Query Cache\u3002
\nQuery cache \u4f5c\u7528\u4e8e\u6574\u4e2a MySQL Instance\uff0c\u4e3b\u8981\u7528\u6765\u7f13\u5b58 MySQL \u4e2d\u7684 ResultSet\uff0c\u4e5f\u5c31\u662f\u4e00\u6761SQL\u8bed\u53e5\u6267\u884c\u7684\u7ed3\u679c\u96c6\uff0c\u6240\u4ee5\u4ec5\u4ec5\u53ea\u80fd\u9488\u5bf9select\u8bed\u53e5\u3002\u5f53\u6211\u4eec\u6253\u5f00\u4e86 Query Cache \u529f\u80fd\uff0cMySQL\u5728\u63a5\u53d7\u5230\u4e00\u6761select\u8bed\u53e5\u7684\u8bf7\u6c42\u540e\uff0c\u5982\u679c\u8be5\u8bed\u53e5\u6ee1\u8db3Query Cache\u7684\u8981\u6c42\uff08\u672a\u663e\u5f0f\u8bf4\u660e\u4e0d\u5141\u8bb8\u4f7f\u7528Query Cache\uff0c\u6216\u8005\u5df2\u7ecf\u663e\u5f0f\u7533\u660e\u9700\u8981\u4f7f\u7528Query Cache\uff09\uff0cMySQL \u4f1a\u76f4\u63a5\u6839\u636e\u9884\u5148\u8bbe\u5b9a\u597d\u7684HASH\u7b97\u6cd5\u5c06\u63a5\u53d7\u5230\u7684select\u8bed\u53e5\u4ee5\u5b57\u7b26\u4e32\u65b9\u5f0f\u8fdb\u884chash\uff0c\u7136\u540e\u5230Query Cache \u4e2d\u76f4\u63a5\u67e5\u627e\u662f\u5426\u5df2\u7ecf\u7f13\u5b58\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5df2\u7ecf\u5728\u7f13\u5b58\u4e2d\uff0c\u8be5select\u8bf7\u6c42\u5c31\u4f1a\u76f4\u63a5\u5c06\u6570\u636e\u8fd4\u56de\uff0c\u4ece\u800c\u7701\u7565\u4e86\u540e\u9762\u6240\u6709\u7684\u6b65\u9aa4\uff08\u5982 SQL\u8bed\u53e5\u7684\u89e3\u6790\uff0c\u4f18\u5316\u5668\u4f18\u5316\u4ee5\u53ca\u5411\u5b58\u50a8\u5f15\u64ce\u8bf7\u6c42\u6570\u636e\u7b49\uff09\uff0c\u6781\u5927\u7684\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n
\u5f53\u7136\uff0cQuery Cache \u4e5f\u6709\u4e00\u4e2a\u81f4\u547d\u7684\u7f3a\u9677\uff0c\u90a3\u5c31\u662f\u5f53\u67d0\u4e2a\u8868\u7684\u6570\u636e\u6709\u4efb\u4f55\u4efb\u4f55\u53d8\u5316\uff0c\u90fd\u4f1a\u5bfc\u81f4\u6240\u6709\u5f15\u7528\u4e86\u8be5\u8868\u7684select\u8bed\u53e5\u5728Query Cache \u4e2d\u7684\u7f13\u5b58\u6570\u636e\u5931\u6548\u3002\u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u7684\u6570\u636e\u53d8\u5316\u975e\u5e38\u9891\u7e41\u7684\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528Query Cache \u53ef\u80fd\u4f1a\u5f97\u4e0d\u507f\u5931\u3002<\/p>\n
Query Cache\u7684\u4f7f\u7528\u9700\u8981\u591a\u4e2a\u53c2\u6570\u914d\u5408\uff0c\u5176\u4e2d\u6700\u4e3a\u5173\u952e\u7684\u662f query_cache_size \u548c query_cache_type \uff0c\u524d\u8005\u8bbe\u7f6e\u7528\u4e8e\u7f13\u5b58 ResultSet \u7684\u5185\u5b58\u5927\u5c0f\uff0c\u540e\u8005\u8bbe\u7f6e\u5728\u4f55\u573a\u666f\u4e0b\u4f7f\u7528 Query Cache\u3002\u5728\u4ee5\u5f80\u7684\u7ecf\u9a8c\u6765\u770b\uff0c\u5982\u679c\u4e0d\u662f\u7528\u6765\u7f13\u5b58\u57fa\u672c\u4e0d\u53d8\u7684\u6570\u636e\u7684MySQL\u6570\u636e\u5e93\uff0cquery_cache_size \u4e00\u822c 256MB \u662f\u4e00\u4e2a\u6bd4\u8f83\u5408\u9002\u7684\u5927\u5c0f\u3002\u5f53\u7136\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8ba1\u7b97Query Cache\u7684\u547d\u4e2d\u7387\uff08Qcache_hits\/(Qcache_hits+Qcache_inserts)*100)\uff09\u6765\u8fdb\u884c\u8c03\u6574\u3002<\/p><\/blockquote>\n
Query Cache \u7ef4\u62a4<\/strong><\/p>\n
MySQL\u662f\u6309\u5757\u8fdb\u884c\u5185\u5b58\u7533\u8bf7\u5206\u914d\u7684\uff0c\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u7cfb\u7edf\u5b58\u5728\u5927\u91cf\u5185\u5b58\u788e\u7247\uff0c\u53ef\u4ee5\u901a\u8fc7\u201cFLUSH QUERY CACHE\u201d\u8bed\u53e5\u8fdb\u884c\u5185\u5b58\u788e\u7247\u6574\u7406\uff0c\u53e6\u59162\u4e2a\u53ef\u4ee5\u7ba1\u7406Query Cache\u7684\u5206\u522b\u662f\uff1aRESET QUERY CACHE\u3001FLUSH TABLES\uff0c\u5b83\u4eec\u5c06\u6e05\u7a7aQuery Cache\u5185\u5bb9\u3002<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<\/li>\n
- Key Cache\/Key Buffer\u00a0\u53c2\u8003<\/a><\/strong>\n
\n
- key_buffer_size\uff1a<\/strong>\u7528\u6765\u8bbe\u7f6e\u7528\u4e8e\u7f13\u5b58 MyISAM\u5b58\u50a8\u5f15\u64ce\u4e2d\u7d22\u5f15\u6587\u4ef6\u7684\u5185\u5b58\u533a\u57df\u5927\u5c0f<\/li>\n
- key_cache_block_size\uff1a<\/strong>\u8bbe\u7f6ekey cache \u5757\u5927\u5c0f<\/li>\n
- key_cache_division_limit\uff1a<\/strong>\u8bbe\u7f6ewarm sub-clain\u7684\u6bd4\u4f8b<\/li>\n
- key_cache_age_threshold\uff1a<\/strong>\u8bbe\u7f6ecache\u4ecewarm sub-clain\u5230hot sub-clain\u7684\u201c\u9600\u503c\u201d
\nKey Buffer \u53ef\u80fd\u662f\u5927\u5bb6\u6700\u4e3a\u719f\u6089\u7684\u4e00\u4e2a MySQL \u7f13\u5b58\u53c2\u6570\u4e86\uff0c\u5c24\u5176\u662f\u5728 MySQL \u6ca1\u6709\u66f4\u6362\u9ed8\u8ba4\u5b58\u50a8\u5f15\u64ce\u7684\u65f6\u5019\uff0c\u5f88\u591a\u670b\u53cb\u53ef\u80fd\u4f1a\u53d1\u73b0\uff0c\u9ed8\u8ba4\u7684 MySQL \u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u6700\u5927\u7684\u4e00\u4e2a\u5185\u5b58\u53c2\u6570\u5c31\u662f\u8fd9\u4e2a\u53c2\u6570\u4e86\u3002key_buffer_size \u53c2\u6570\u7528\u6765\u8bbe\u7f6e\u7528\u4e8e\u7f13\u5b58 MyISAM\u5b58\u50a8\u5f15\u64ce\u4e2d\u7d22\u5f15\u6587\u4ef6\u7684\u5185\u5b58\u533a\u57df\u5927\u5c0f\u3002\u5982\u679c\u6211\u4eec\u6709\u8db3\u591f\u7684\u5185\u5b58\uff0c\u8fd9\u4e2a\u7f13\u5b58\u533a\u57df\u6700\u597d\u662f\u80fd\u591f\u5b58\u653e\u4e0b\u6211\u4eec\u6240\u6709\u7684 MyISAM \u5f15\u64ce\u8868\u7684\u6240\u6709\u7d22\u5f15\uff0c\u4ee5\u5c3d\u53ef\u80fd\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n
\u5408\u7406\u7684\u503c\u53d6\u51b3\u4e8e\u7d22\u5f15\u5927\u5c0f\u3001\u6570\u636e\u91cf\u4ee5\u53ca\u8d1f\u8f7d \u2014 \u8bb0\u4f4f\uff0cMyISAM\u8868\u4f1a\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u7f13\u5b58\u6765\u7f13\u5b58\u6570\u636e<\/em>\uff0c\u56e0\u6b64\u9700\u8981\u7559\u51fa\u90e8\u5206\u5185\u5b58\u7ed9\u5b83\u4eec\uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\u6570\u636e\u6bd4\u7d22\u5f15\u5927\u591a\u4e86\u3002\u5c3d\u7ba1\u5982\u6b64\uff0c\u9700\u8981\u603b\u662f\u68c0\u67e5\u662f\u5426\u6240\u6709\u7684 key_buffer \u90fd\u88ab\u5229\u7528\u4e86 \u2014 .MYI \u6587\u4ef6\u53ea\u6709 1GB\uff0c\u800c key_buffer \u5374\u8bbe\u7f6e\u4e3a 4GB \u7684\u60c5\u51b5\u662f\u975e\u5e38\u5c11\u7684\u3002\u8fd9\u4e48\u505a\u592a\u6d6a\u8d39\u4e86\u3002\u5982\u679c\u4f60\u5f88\u5c11\u4f7f\u7528MyISAM\u8868\uff0c\u90a3\u4e48\u4e5f\u4fdd\u7559\u4f4e\u4e8e 16-32MB \u7684 key_buffer_size \u4ee5\u9002\u5e94\u7ed9\u4e88\u78c1\u76d8\u7684\u4e34\u65f6\u8868\u7d22\u5f15\u6240\u9700\u3002<\/em><\/p>\n
\u5982\u679c\u8bbe\u7f6ekey_cache_division_limit,MySQL\u5c06\u91c7\u7528Midpoint Insertion Strategy<\/a>\u5c06key cache\u5206\u6210warm sub-clain\u548chot sub-clain\u4e24\u90e8\u5206\uff0ccache block \u5c06\u6839\u636ekey_cache_age_threshold\u5728\u4e24\u4e2asub-clain\u4e2d\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u4e3a\u51e0\u4e2a\u8868\u5355\u72ec\u8bbe\u7f6eKey Cache\u7a7a\u95f4<\/a>\uff0c\u5e76\u9884\u52a0\u8f7d<\/a>\u8868\u7d22\u5f15\u5230\u6307\u5b9aKey Cache<\/p>\n
mysql> SET GLOBAL keycache1.key_buffer_size=128*1024; #\u521b\u5efaKey Cache\r\nmysql> SET GLOBAL keycache1.key_buffer_size=0; #\u9500\u6bc1Key Cache\r\nmysql> CACHE INDEX t1, t2, t3 IN hot_cache; #\u8bbe\u7f6e\u6307\u5b9a\u8868\u5230\u6307\u5b9aKey Cache\r\nmysql> LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES; #\u9884\u52a0\u8f7d\u7d22\u5f15\u5230Key Cache<\/pre>\n\u6b64\u5916\uff0c\u5f53\u6211\u4eec\u5728\u4f7f\u7528MyISAM \u5b58\u50a8\u7684\u65f6\u5019\u6709\u4e00\u4e2a\u53ca\u5176\u91cd\u8981\u7684\u70b9\u9700\u8981\u6ce8\u610f\uff0c\u7531\u4e8e MyISAM \u5f15\u64ce\u7684\u7279\u6027\u9650\u5236\u4e86\u4ed6\u4ec5\u4ec5\u53ea\u4f1a\u7f13\u5b58\u7d22\u5f15\u5757\u5230\u5185\u5b58\u4e2d\uff0c\u800c\u4e0d\u4f1a\u7f13\u5b58\u8868\u6570\u636e\u5e93\u5757\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u7684 SQL \u4e00\u5b9a\u8981\u5c3d\u53ef\u80fd\u8ba9\u8fc7\u6ee4\u6761\u4ef6\u90fd\u5728\u7d22\u5f15\u4e2d\uff0c\u4ee5\u4fbf\u8ba9\u7f13\u5b58\u5e2e\u52a9\u6211\u4eec\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u3002<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<\/li>\n
- InnoDB Buffer Pool<\/strong>\n
\n
- innodb_buffer_pool_size\uff1a<\/strong>\u7c7b\u4f3c\u4e8e MyISAM \u5b58\u50a8\u5f15\u64ce\u7684 key_buffer_size \u53c2\u6570\uff0c\u9664\u4e5f\u5b58\u50a8\u7d22\u5f15\u5916\uff0c\u8fd8\u5b58\u50a8\u6570\u636e.<\/li>\n
- innodb_additional_mem_pool_size\uff1a<\/strong>\u8bbe\u7f6e\u4e86InnoDB\u5b58\u50a8\u5f15\u64ce\u7528\u6765\u5b58\u653e\u6570\u636e\u5b57\u5178\u4fe1\u606f\u4ee5\u53ca\u4e00\u4e9b\u5185\u90e8\u6570\u636e\u7ed3\u6784\u7684\u5185\u5b58\u7a7a\u95f4\u5927\u5c0f.<\/li>\n
- innodb_log_buffer_size\uff1a<\/strong>InnoDB \u5b58\u50a8\u5f15\u64ce\u7684\u4e8b\u52a1\u65e5\u5fd7\u6240\u4f7f\u7528\u7684\u7f13\u51b2\u533a,\u5728\u5199\u4e8b\u52a1\u65e5\u5fd7\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u5148\u5c06\u4fe1\u606f\u5199\u5165 Innofb Log Buffer \u4e2d,\u518d\u5c06\u65e5\u5fd7\u540c\u6b65\u5230\u78c1\u76d8.<\/li>\n
- innodb_flush_log_trx_commit \uff1a<\/strong>\u8bbe\u7f6e\u4e8b\u52a1\u63d0\u4ea4\u5230log file\u53ca\u6587\u4ef6\u7cfb\u7edf\u5230\u78c1\u76d8\u7684\u540c\u6b65\u64cd\u4f5c
\ninnodb_flush_log_trx_commit \u53c2\u6570\u5bf9 InnoDB Log \u7684\u5199\u5165\u6027\u80fd\u6709\u975e\u5e38\u5173\u952e\u7684\u5f71\u54cd\u3002\u8be5\u53c2\u6570\u53ef\u4ee5\u8bbe\u7f6e\u4e3a0\uff0c1\uff0c2\uff0c\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n
0\uff1alog buffer\u4e2d\u7684\u6570\u636e\u5c06\u4ee5\u6bcf\u79d2\u4e00\u6b21\u7684\u9891\u7387\u5199\u5165\u5230log file\u4e2d\uff0c\u4e14\u540c\u65f6\u4f1a\u8fdb\u884c\u6587\u4ef6\u7cfb\u7edf\u5230\u78c1\u76d8\u7684\u540c\u6b65\u64cd\u4f5c\uff0c\u4f46\u662f\u6bcf\u4e2a\u4e8b\u52a1\u7684commit\u5e76\u4e0d\u4f1a\u89e6\u53d1\u4efb\u4f55log buffer \u5230log file\u7684\u5237\u65b0\u6216\u8005\u6587\u4ef6\u7cfb\u7edf\u5230\u78c1\u76d8\u7684\u5237\u65b0\u64cd\u4f5c\uff1b<\/p>\n
1\uff1a\u5728\u6bcf\u6b21\u4e8b\u52a1\u63d0\u4ea4\u7684\u65f6\u5019\u5c06log buffer \u4e2d\u7684\u6570\u636e\u90fd\u4f1a\u5199\u5165\u5230log file\uff0c\u540c\u65f6\u4e5f\u4f1a\u89e6\u53d1\u6587\u4ef6\u7cfb\u7edf\u5230\u78c1\u76d8\u7684\u540c\u6b65\uff1b<\/p>\n
2\uff1a\u4e8b\u52a1\u63d0\u4ea4\u4f1a\u89e6\u53d1log buffer \u5230log file\u7684\u5237\u65b0\uff0c\u4f46\u5e76\u4e0d\u4f1a\u89e6\u53d1\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u5230\u78c1\u76d8\u7684\u540c\u6b65\u3002\u6b64\u5916\uff0c\u6bcf\u79d2\u4f1a\u6709\u4e00\u6b21\u6587\u4ef6\u7cfb\u7edf\u5230\u78c1\u76d8\u540c\u6b65\u64cd\u4f5c\u3002<\/p>\n
\u6b64\u5916\uff0cMySQL\u6587\u6863\u4e2d\u8fd8\u63d0\u5230\uff0c\u8fd9\u51e0\u79cd\u8bbe\u7f6e\u4e2d\u7684\u6bcf\u79d2\u540c\u6b65\u4e00\u6b21\u7684\u673a\u5236\uff0c\u53ef\u80fd\u5e76\u4e0d\u4f1a\u5b8c\u5168\u786e\u4fdd\u975e\u5e38\u51c6\u786e\u7684\u6bcf\u79d2\u5c31\u4e00\u5b9a\u4f1a\u53d1\u751f\u540c\u6b65\uff0c\u8fd8\u53d6\u51b3\u4e8e\u8fdb\u7a0b\u8c03\u5ea6\u7684\u95ee\u9898\u3002\u5b9e\u9645\u4e0a\uff0cInnoDB \u80fd\u5426\u771f\u6b63\u6ee1\u8db3\u6b64\u53c2\u6570\u6240\u8bbe\u7f6e\u503c\u4ee3\u8868\u7684\u610f\u4e49\u6b63\u5e38 Recovery \u8fd8\u662f\u53d7\u5230\u4e86\u4e0d\u540c OS \u4e0b\u6587\u4ef6\u7cfb\u7edf\u4ee5\u53ca\u78c1\u76d8\u672c\u8eab\u7684\u9650\u5236\uff0c\u53ef\u80fd\u6709\u4e9b\u65f6\u5019\u5728\u5e76\u6ca1\u6709\u771f\u6b63\u5b8c\u6210\u78c1\u76d8\u540c\u6b65\u7684\u60c5\u51b5\u4e0b\u4e5f\u4f1a\u544a\u8bc9 mysqld \u5df2\u7ecf\u5b8c\u6210\u4e86\u78c1\u76d8\u540c\u6b65\u3002<\/p><\/blockquote>\n<\/li>\n
- innodb_max_dirty_pages_pct\uff1a<\/strong>\u7528\u6765\u63a7\u5236\u5728 InnoDB Buffer Pool \u4e2d\u53ef\u4ee5\u4e0d\u7528\u5199\u5165\u6570\u636e\u6587\u4ef6\u4e2d\u7684Dirty Page \u7684\u6bd4\u4f8b\uff08\u5df2\u7ecf\u88ab\u4fee\u4f46\u8fd8\u6ca1\u6709\u4ece\u5185\u5b58\u4e2d\u5199\u5165\u5230\u6570\u636e\u6587\u4ef6\u7684\u810f\u6570\u636e\uff09\u3002
\nInnoDB Buffer Pool\u4e0eMyISAM\u7684Key Cache\u7c7b\u4f3c\uff0c\u6240\u4e0d\u540c\u7684\u662fInnoDB Buffer Pool\u4e0d\u4ec5\u4fdd\u5b58\u8868\u7d22\u5f15\uff0c\u8fd8\u4fdd\u5b58\u8868\u6570\u636e \u3002<\/p>\n
\u5982\u679c\u4e0d\u4f7f\u7528InnoDB\u5b58\u50a8\u5f15\u64ce\uff0c\u53ef\u4ee5\u4e0d\u7528\u8c03\u6574\u53c2\u6570innodb_buffer_pool_size<\/strong>\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528\uff0c\u5728\u5185\u5b58\u5141\u8bb8\u7684\u60c5\u51b5\u4e0b\uff0c\u5c3d\u53ef\u80fd\u5c06\u6240\u6709\u7684InnoDB\u6570\u636e\u6587\u4ef6\u5b58\u653e\u5982\u5185\u5b58\u4e2d\uff0c\u540c\u6837\u4e5f\u662f\u201c\u8d8a\u5927\u8d8a\u597d\u201d\u3002<\/p>\n
innodb_max_dirty_pages_pct\uff0c\u6839\u636e\u4ee5\u5f80\u7684\u7ecf\u9a8c\uff0c\u91cd\u542f\u6062\u590d\u7684\u6570\u636e\u5982\u679c\u8981\u8d85\u8fc71GB\u7684\u8bdd\uff0c\u542f\u52a8\u901f\u5ea6\u4f1a\u6bd4\u8f83\u6162\uff0c\u51e0\u4e4e\u96be\u4ee5\u63a5\u53d7\uff0c\u6240\u4ee5\u5efa\u8bae\u4e0d\u5927\u4e8e 1GB\/innodb_buffer_pool_size(GB)*100 \u8fd9\u4e2a\u503c\u3002\u5f53\u7136\uff0c\u5982\u679c\u4f60\u80fd\u591f\u5fcd\u53d7\u542f\u52a8\u65f6\u95f4\u6bd4\u8f83\u957f\uff0c\u800c\u4e14\u5e0c\u671b\u5c3d\u91cf\u51cf\u5c11\u5185\u5b58\u81f3\u78c1\u76d8\u7684flush\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u503c\u8c03\u6574\u523090\uff0c\u4f46\u4e0d\u5efa\u8bae\u8d85\u8fc790<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<\/li>\n
- table_cache\/table_open_cache\uff1a<\/strong>\u8868\u7f13\u5b58\u533a\u4e3b\u8981\u7528\u6765\u7f13\u5b58\u8868\u6587\u4ef6\u7684\u6587\u4ef6\u53e5\u67c4\u4fe1\u606f\uff0cMySQL\u6240\u6709\u7ebf\u7a0b\u6253\u5f00\u8868\u7684\u6570\u91cf\uff0c\u5305\u62ec\u4e34\u65f6\u8868\u4ee5\u53camysqld\u9700\u8981\u7684\u4e00\u4e9b\u989d\u5916\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u76f8\u5173\u53c2\u6570\u8fd8\u6709max_connections.
\n\u5f53\u7528\u6237\u6267\u884cSQL\u662f\uff0c\u6bcf\u4e2a\u8fde\u63a5\u8fdb\u6765\uff0c\u90fd\u4f1a\u81f3\u5c11\u6253\u5f00\u4e00\u4e2a\u8868\u7f13\u5b58\u3002\u56e0\u6b64\uff0c table_cache \u7684\u5927\u5c0f\u5e94\u4e0e max_connections \u7684\u8bbe\u7f6e\u6709\u5173\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e 200 \u4e2a\u5e76\u884c\u8fd0\u884c\u7684\u8fde\u63a5\uff0c\u5e94\u8be5\u8ba9\u8868\u7684\u7f13\u5b58\u81f3\u5c11\u6709 200 \u00d7 N \uff0c\u8fd9\u91cc N \u662f\u5e94\u7528\u53ef\u4ee5\u6267\u884c\u7684\u67e5\u8be2\u7684\u4e00\u4e2a\u8054\u63a5\u4e2d\u8868\u7684\u6700\u5927\u6570\u91cf\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u4e3a\u4e34\u65f6\u8868\u548c\u6587\u4ef6\u4fdd\u7559\u4e00\u4e9b\u989d\u5916\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002<\/p><\/blockquote>\n<\/li>\n
- max_connections\uff1a<\/strong>MySQL\u6700\u5927\u540c\u65f6\u8fde\u63a5\u6570\uff0c\u8fd9\u4e2a\u503c\u5982\u679c\u8fc7\u4f4e\u4f1a\u51fa\u73b0\u201cToo many connections\u201d\u9519\u8bef.<\/li>\n
- thread_cache_size\uff1a<\/strong>\u7ebf\u7a0b\u7f13\u5b58\u6570\u91cf\uff0c\u53ef\u901a\u8fc7\u67e5\u770b\u72b6\u6001\u53d8\u91cf”connections”\u3001”threads_created”\u8fdb\u884c\u8c03\u6574.
\n\u8fde\u63a5\u7ebf\u7a0b\u7f13\u5b58\u662f MySQL \u4e3a\u4e86\u63d0\u9ad8\u521b\u5efa\u8fde\u63a5\u7ebf\u7a0b\u7684\u6548\u7387\uff0c\u5c06\u90e8\u5206\u7a7a\u95f2\u7684\u8fde\u63a5\u7ebf\u7a0b\u4fdd\u6301\u5728\u4e00\u4e2a\u7f13\u5b58\u533a\u4ee5\u5907\u65b0\u8fdb\u8fde\u63a5\u8bf7\u6c42\u7684\u65f6\u5019\u4f7f\u7528\uff0c\u8fd9\u5c24\u5176\u5bf9\u90a3\u4e9b\u4f7f\u7528\u77ed\u8fde\u63a5\u7684\u5e94\u7528\u7a0b\u5e8f\u6765\u8bf4\u53ef\u4ee5\u6781\u5927\u7684\u63d0\u9ad8\u521b\u5efa\u8fde\u63a5\u7684\u6548\u7387\u3002\u5f53\u6211\u4eec\u901a\u8fc7 thread_cache_size \u8bbe\u7f6e\u4e86\u8fde\u63a5\u7ebf\u7a0b\u7f13\u5b58\u6c60\u53ef\u4ee5\u7f13\u5b58\u7684\u8fde\u63a5\u7ebf\u7a0b\u7684\u5927\u5c0f\u4e4b\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7(Connections \u2013 Threads_created) \/ Connections * 100% \u8ba1\u7b97\u51fa\u8fde\u63a5\u7ebf\u7a0b\u7f13\u5b58\u7684\u547d\u4e2d\u7387\u3002\u6ce8\u610f\uff0c\u8fd9\u91cc\u8bbe\u7f6e\u7684\u662f\u53ef\u4ee5\u7f13\u5b58\u7684\u8fde\u63a5\u7ebf\u7a0b\u7684\u6570\u76ee\uff0c\u800c\u4e0d\u662f\u5185\u5b58\u7a7a\u95f4\u7684\u5927\u5c0f\u3002<\/em><\/p><\/blockquote>\n<\/li>\n
- sort_buffer_size\uff1a<\/strong>MySQL\u4e3a\u6bcf\u4e2a\u9700\u8981\u8fdb\u884c\u6392\u5e8f\u64cd\u4f5c\u7684\u7ebf\u7a0b\u5206\u914d\u7684\u7f13\u51b2\u533a\uff0c\u5b83\u53ef\u4ee5\u5f71\u54cdOrder By\u548cGroup By\u64cd\u4f5c.
\n\u589e\u5927sort_buffer_size \u4f1a\u51cf\u5c11Sort_merge_passes\u548c\u521b\u5efa\u4e34\u65f6\u6587\u4ef6\u7684\u6b21\u6570\uff0c\u4f46\u76f2\u76ee\u589e\u52a0\u5e76\u4e0d\u4e00\u5b9a\u80fd\u63d0\u9ad8\u901f\u5ea6\u3002<\/p><\/blockquote>\n<\/li>\n
- open_files_limit\uff1a\u6587\u4ef6\u6253\u5f00\u6570
\n\u5f53open_files\u5927\u4e8eopen_files_limit\u503c\u65f6\uff0cmysql\u6570\u636e\u5e93\u5c31\u4f1a\u53d1\u751f\u5361\u4f4f\u7684\u73b0\u8c61\uff0c\u5bfc\u81f4web\u670d\u52a1\u5668\u6253\u5f00\u4e0d\u54cd\u5e94\u7684\u9875\u9762\u3002<\/p>\n\u67e5\u770bopen_files\u547d\u4ee4
\nshow global status like ‘open_files’;<\/em>
\n\u67e5\u770bopen_files_limit\u547d\u4ee4
\nshow variables like ‘open_files_limit’;<\/em>
\n\u7406\u60f3\u503c\uff1a\u7406\u60f3\u503c\uff1aopen_files \/ open_files_limit *100% \u2264 75%<\/p><\/blockquote>\n<\/li>\n- continue….<\/li>\n<\/ol>\n
-EOF-<\/div>\n\u53c2\u8003\u8d44\u6599\uff1a<\/strong><\/div>\n\n\n
- http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/server-system-variables.html<\/a><\/li>\n
- http:\/\/www.orczhou.com\/index.php\/2010\/01\/myisam-key-buffer-1\/<\/a><\/li>\n
- http:\/\/isky000.com\/database\/mysql-perfornamce-tuning-cache-parameter<\/a><\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"
\u672c\u6587\u5c31\u5e38\u89c1MySQL\u8fd0\u884c\u53c2\u6570\u505a\u8be6\u7ec6\u5217\u4e3e\u4e0e\u8bf4\u660e\uff0c\u5e76\u5bf9\u5404\u53c2\u6570\u7684\u8bbe\u7f6e\u6761\u4ef6\u505a\u5c3d\u53ef\u80fd\u8be6\u5c3d\u7684\u89e3\u91ca\uff0c\u7531\u4e8eMySQL\u914d\u7f6e\u53c2\u6570\u6bd4 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[132,28,27],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1309"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1309"}],"version-history":[{"count":30,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1309\/revisions"}],"predecessor-version":[{"id":1444,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1309\/revisions\/1444"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}