{"id":173,"date":"2015-06-11T11:13:43","date_gmt":"2015-06-11T03:13:43","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=173"},"modified":"2015-06-11T19:44:51","modified_gmt":"2015-06-11T11:44:51","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e5%8f%91%e5%b1%95%e5%91%a8%e6%9c%9f%e4%b8%ad%e6%89%80%e9%9d%a2%e4%b8%b4%e7%9a%84%e9%97%ae%e9%a2%98%e5%8f%8a%e4%bc%98%e5%8c%96%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=173","title":{"rendered":"MySQL\u6570\u636e\u5e93\u53d1\u5c55\u5468\u671f\u4e2d\u6240\u9762\u4e34\u7684\u95ee\u9898\u53ca\u4f18\u5316\u65b9\u6848"},"content":{"rendered":"<p>\n\t\u8f6c\u81ea\uff1a<span class=\"profile_nickname\">\u7a0b\u5e8f\u5458\u65e5\u5fd7 <\/span>http:\/\/mp.weixin.qq.com\/s?__biz=MzAxNjAzMTQyMA==&amp;mid=206362257&amp;idx=1&amp;sn=dac0a9795d59c94f6fa70b9379485b0e&amp;scene=2&amp;from=timeline&amp;isappinstalled=0#rd\n<\/p>\n<p>\n\t<span>\u672c\u535a\u6587\u4e3b\u8981\u8c08MySQL\u6570\u636e\u5e93\u53d1\u5c55\u5468\u671f\u4e2d\u6240\u9762\u4e34\u7684\u95ee\u9898\u53ca\u4f18\u5316\u65b9\u6848\uff0c\u6682\u4e14\u629b\u5f00\u524d\u7aef\u5e94\u7528\u4e0d\u8bf4\uff0c\u5927\u81f4\u5206\u4e3a\u4ee5\u4e0b\u4e94\u4e2a\u9636\u6bb5\uff1a<\/span>\n<\/p>\n<h3>\n\t<span>1\u3001\u6570\u636e\u5e93\u8868\u8bbe\u8ba1<\/span><br \/>\n<\/h3>\n<p>\n\t<span>\u9879\u76ee\u7acb\u9879\u540e\uff0c\u5f00\u53d1\u90e8\u6839\u636e\u4ea7\u54c1\u90e8\u9700\u6c42\u5f00\u53d1\u9879\u76ee\uff0c\u5f00\u53d1\u5de5\u7a0b\u5e08\u5de5\u4f5c\u5176\u4e2d\u4e00\u90e8\u5206\u5c31\u662f\u5bf9\u8868\u7ed3\u6784\u8bbe\u8ba1\u3002\u5bf9\u4e8e\u6570\u636e\u5e93\u6765\u8bf4\uff0c\u8fd9\u70b9\u5f88\u91cd\u8981\uff0c\u5982\u679c\u8bbe\u8ba1\u4e0d\u5f53\uff0c\u4f1a\u76f4\u63a5\u5f71\u54cd\u8bbf\u95ee\u901f\u5ea6\u548c\u7528\u6237\u4f53\u9a8c\u3002\u5f71\u54cd\u7684\u56e0\u7d20\u5f88\u591a\uff0c\u6bd4\u5982\u6162\u67e5\u8be2\u3001\u4f4e\u6548\u7684\u67e5\u8be2\u8bed\u53e5\u3001\u6ca1\u6709\u9002\u5f53\u5efa\u7acb\u7d22\u5f15\u3001\u6570\u636e\u5e93\u5835\u585e\uff08\u6b7b\u9501\uff09\u7b49\u3002\u5f53\u7136\uff0c\u6709\u6d4b\u8bd5\u5de5\u7a0b\u5e08\u7684\u56e2\u961f\uff0c\u4f1a\u505a\u538b\u529b\u6d4b\u8bd5\uff0c\u627ebug\u3002\u5bf9\u4e8e\u6ca1\u6709\u6d4b\u8bd5\u5de5\u7a0b\u5e08\u7684\u56e2\u961f\u6765\u8bf4\uff0c\u5927\u591a\u6570\u5f00\u53d1\u5de5\u7a0b\u5e08\u521d\u671f\u4e0d\u4f1a\u592a\u591a\u8003\u8651\u6570\u636e\u5e93\u8bbe\u8ba1\u662f\u5426\u5408\u7406\uff0c\u800c\u662f\u5c3d\u5feb\u5b8c\u6210\u529f\u80fd\u5b9e\u73b0\u548c\u4ea4\u4ed8\uff0c\u7b49\u9879\u76ee\u6709\u4e00\u5b9a\u8bbf\u95ee\u91cf\u540e\uff0c\u9690\u85cf\u7684\u95ee\u9898\u5c31\u4f1a\u66b4\u9732\uff0c\u8fd9\u65f6\u518d\u53bb\u4fee\u6539\u5c31\u4e0d\u662f\u8fd9\u4e48\u5bb9\u6613\u7684\u4e8b\u4e86\u3002<\/span>\n<\/p>\n<h3>\n\t<span>2\u3001\u6570\u636e\u5e93\u90e8\u7f72<\/span><br \/>\n<\/h3>\n<p>\n\t<span>\u8be5\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u51fa\u573a\u4e86\uff0c\u9879\u76ee\u521d\u671f\u8bbf\u95ee\u91cf\u4e0d\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u5355\u53f0\u90e8\u7f72\u8db3\u4ee5\u5e94\u5bf9\u57281500\u5de6\u53f3\u7684QPS\uff08\u6bcf\u79d2\u67e5\u8be2\u7387\uff09\u3002\u8003\u8651\u5230\u9ad8\u53ef\u7528\u6027\uff0c\u53ef\u91c7\u7528MySQL\u4e3b\u4ece\u590d\u5236+Keepalived\u505a\u53cc\u51fb\u70ed\u5907\uff0c\u5e38\u89c1\u96c6\u7fa4\u8f6f\u4ef6\u6709Keepalived\u3001Heartbeat\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u53cc\u673a\u70ed\u5907\u535a\u6587\uff1a<\/span><span>http:\/\/lizhenliang.blog.51cto.com\/7876557\/1362313<\/span>\n<\/p>\n<h3>\n\t<span>3\u3001\u6570\u636e\u5e93\u6027\u80fd\u4f18\u5316<\/span><br \/>\n<\/h3>\n<p>\n\t<span>\u5982\u679c\u5c06MySQL\u90e8\u7f72\u5230\u666e\u901a\u7684X86\u670d\u52a1\u5668\u4e0a\uff0c\u5728\u4e0d\u7ecf\u8fc7\u4efb\u4f55\u4f18\u5316\u60c5\u51b5\u4e0b\uff0cMySQL\u7406\u8bba\u503c\u6b63\u5e38\u53ef\u4ee5\u5904\u74062000\u5de6\u53f3QPS\uff0c\u7ecf\u8fc7\u4f18\u5316\u540e\uff0c\u6709\u53ef\u80fd\u4f1a\u63d0\u5347\u52302500\u5de6\u53f3QPS\uff0c\u5426\u5219\uff0c\u8bbf\u95ee\u91cf\u5f53\u8fbe\u52301500\u5de6\u53f3\u5e76\u53d1\u8fde\u63a5\u65f6\uff0c\u6570\u636e\u5e93\u5904\u7406\u6027\u80fd\u5c31\u4f1a\u53d8\u6162\uff0c\u800c\u4e14\u786c\u4ef6\u8d44\u6e90\u8fd8\u5f88\u5bcc\u88d5\uff0c\u8fd9\u65f6\u5c31\u8be5\u8003\u8651\u8f6f\u4ef6\u95ee\u9898\u4e86\u3002\u90a3\u4e48\u600e\u6837\u8ba9\u6570\u636e\u5e93\u6700\u5927\u5316\u53d1\u6325\u6027\u80fd\u5462\uff1f\u4e00\u65b9\u9762\u53ef\u4ee5\u5355\u53f0\u8fd0\u884c\u591a\u4e2aMySQL\u5b9e\u4f8b\u8ba9\u670d\u52a1\u5668\u6027\u80fd\u53d1\u6325\u5230\u6700\u5927\u5316\uff0c\u53e6\u4e00\u65b9\u9762\u662f\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u4f18\u5316\uff0c\u5f80\u5f80\u64cd\u4f5c\u7cfb\u7edf\u548c\u6570\u636e\u5e93\u9ed8\u8ba4\u914d\u7f6e\u90fd\u6bd4\u8f83\u4fdd\u5b88\uff0c\u4f1a\u5bf9\u6570\u636e\u5e93\u53d1\u6325\u6709\u4e00\u5b9a\u9650\u5236\uff0c\u53ef\u5bf9\u8fd9\u4e9b\u914d\u7f6e\u8fdb\u884c\u9002\u5f53\u7684\u8c03\u6574\uff0c\u5c3d\u53ef\u80fd\u7684\u5904\u7406\u66f4\u591a\u8fde\u63a5\u6570\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u5177\u4f53\u4f18\u5316\u6709\u4ee5\u4e0b\u4e09\u4e2a\u5c42\u9762\uff1a<\/span>\n<\/p>\n<h4>\n\t<span>3.1 \u6570\u636e\u5e93\u914d\u7f6e\u4f18\u5316<\/span><br \/>\n<\/h4>\n<p>\n\t<span>MySQL\u5e38\u7528\u6709\u4e24\u79cd\u5b58\u50a8\u5f15\u64ce\uff0c\u4e00\u4e2a\u662fMyISAM\uff0c\u4e0d\u652f\u6301\u4e8b\u52a1\u5904\u7406\uff0c\u8bfb\u6027\u80fd\u5904\u7406\u5feb\uff0c\u8868\u7ea7\u522b\u9501\u3002\u53e6\u4e00\u4e2a\u662fInnoDB\uff0c\u652f\u6301\u4e8b\u52a1\u5904\u7406\uff08ACID\uff09\uff0c\u8bbe\u8ba1\u76ee\u6807\u662f\u4e3a\u5904\u7406\u5927\u5bb9\u91cf\u6570\u636e\u53d1\u6325\u6700\u5927\u5316\u6027\u80fd\uff0c\u884c\u7ea7\u522b\u9501\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u8868\u9501\uff1a\u5f00\u9500\u5c0f\uff0c\u9501\u5b9a\u7c92\u5ea6\u5927\uff0c\u53d1\u751f\u6b7b\u9501\u6982\u7387\u9ad8\uff0c\u76f8\u5bf9\u5e76\u53d1\u4e5f\u4f4e\u3002<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t\u884c\u9501\uff1a\u5f00\u9500\u5927\uff0c\u9501\u5b9a\u7c92\u5ea6\u5c0f\uff0c\u53d1\u751f\u6b7b\u9501\u6982\u7387\u4f4e\uff0c\u76f8\u5bf9\u5e76\u53d1\u4e5f\u9ad8\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u8868\u9501\u548c\u884c\u9501\u5462\uff1f\u4e3b\u8981\u662f\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4e00\u4e2a\u7528\u6237\u5728\u64cd\u4f5c\u4e00\u5f20\u8868\uff0c\u5176\u4ed6\u7528\u6237\u4e5f\u60f3\u64cd\u4f5c\u8fd9\u5f20\u8868\uff0c\u90a3\u4e48\u5c31\u8981\u7b49\u7b2c\u4e00\u4e2a\u7528\u6237\u64cd\u4f5c\u5b8c\uff0c\u5176\u4ed6\u7528\u6237\u624d\u80fd\u64cd\u4f5c\uff0c\u8868\u9501\u548c\u884c\u9501\u5c31\u662f\u8fd9\u4e2a\u4f5c\u7528\u3002\u5426\u5219\u591a\u4e2a\u7528\u6237\u540c\u65f6\u64cd\u4f5c\u4e00\u5f20\u8868\uff0c\u80af\u5b9a\u4f1a\u6570\u636e\u4ea7\u751f\u51b2\u7a81\u6216\u8005\u5f02\u5e38\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u6839\u636e\u4ee5\u4e0a\u770b\u6765\uff0c\u4f7f\u7528InnoDB\u5b58\u50a8\u5f15\u64ce\u662f\u6700\u597d\u7684\u9009\u62e9\uff0c\u4e5f\u662fMySQL5.5\u4ee5\u540e\u7248\u672c\u4e2d\u9ed8\u8ba4\u5b58\u50a8\u5f15\u64ce\u3002\u6bcf\u4e2a\u5b58\u50a8\u5f15\u64ce\u76f8\u5173\u8054\u53c2\u6570\u6bd4\u8f83\u591a\uff0c\u4ee5\u4e0b\u5217\u51fa\u4e3b\u8981\u5f71\u54cd\u6570\u636e\u5e93\u6027\u80fd\u7684\u53c2\u6570\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u516c\u5171\u53c2\u6570\u9ed8\u8ba4\u503c\uff1a<\/span>\n<\/p>\n<pre>\r\n<span>max_connections = 151\r\n#\u540c\u65f6\u5904\u7406\u6700\u5927\u8fde\u63a5\u6570\uff0c\u63a8\u8350\u8bbe\u7f6e\u6700\u5927\u8fde\u63a5\u6570\u662f\u4e0a\u9650\u8fde\u63a5\u6570\u768480%\u5de6\u53f3\r\nsort_buffer_size = 2M\r\n#\u67e5\u8be2\u6392\u5e8f\u65f6\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u53ea\u5bf9order by\u548cgroup by\u8d77\u4f5c\u7528\uff0c\u53ef\u589e\u5927\u6b64\u503c\u4e3a16M\r\nquery_cache_limit = 1M\r\n#\u67e5\u8be2\u7f13\u5b58\u9650\u5236\uff0c\u53ea\u67091M\u4ee5\u4e0b\u67e5\u8be2\u7ed3\u679c\u624d\u4f1a\u88ab\u7f13\u5b58\uff0c\u4ee5\u514d\u7ed3\u679c\u6570\u636e\u8f83\u5927\u628a\u7f13\u5b58\u6c60\u8986\u76d6\r\nquery_cache_size = 16M\r\n#\u67e5\u770b\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u7528\u4e8e\u7f13\u5b58SELECT\u67e5\u8be2\u7ed3\u679c\uff0c\u4e0b\u4e00\u6b21\u6709\u540c\u6837SELECT\u67e5\u8be2\u5c06\u76f4\u63a5\u4ece\u7f13\u5b58\u6c60\u8fd4\u56de\u7ed3\u679c\uff0c\u53ef\u9002\u5f53\u6210\u500d\u589e\u52a0\u6b64\u503c\r\nopen_files_limit = 1024\r\n#\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\uff0c\u5982\u679cshow global status like &#39;open_files&#39;\u67e5\u770b\u7684\u503c\u7b49\u4e8e\u6216\u8005\u5927\u4e8eopen_files_limit\u503c\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u65e0\u6cd5\u8fde\u63a5\u6570\u636e\u5e93\u6216\u5361\u6b7b<\/span><\/pre>\n<p>\n\t<span>MyISAM\u53c2\u6570\u9ed8\u8ba4\u503c\uff1a<\/span>\n<\/p>\n<pre>\r\n<span>key_buffer_size = 16M\r\n#\u7d22\u5f15\u7f13\u5b58\u533a\u5927\u5c0f\uff0c\u4e00\u822c\u8bbe\u7f6e\u7269\u7406\u5185\u5b58\u768430-40%\r\nread_buffer_size = 128K\r\n#\u8bfb\u64cd\u4f5c\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u63a8\u8350\u8bbe\u7f6e16M\u621632M<\/span><\/pre>\n<p>\n\t<span>InnoDB\u53c2\u6570\u9ed8\u8ba4\u503c\uff1a<\/span>\n<\/p>\n<pre>\r\n<span>innodb_buffer_pool_size = 128M\r\n#\u7d22\u5f15\u548c\u6570\u636e\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u4e00\u822c\u8bbe\u7f6e\u7269\u7406\u5185\u5b58\u768460%-70%\r\ninnodb_buffer_pool_instances = 1\r\n#\u7f13\u51b2\u6c60\u5b9e\u4f8b\u4e2a\u6570\uff0c\u63a8\u8350\u8bbe\u7f6e4\u4e2a\u62168\u4e2a\r\ninnodb_flush_log_at_trx_commit = 1\r\n#\u5173\u952e\u53c2\u6570\uff0c0\u4ee3\u8868\u5927\u7ea6\u6bcf\u79d2\u5199\u5165\u5230\u65e5\u5fd7\u5e76\u540c\u6b65\u5230\u78c1\u76d8\uff0c\u6570\u636e\u5e93\u6545\u969c\u4f1a\u4e22\u59311\u79d2\u5de6\u53f3\u4e8b\u52a1\u6570\u636e\u30021\u4e3a\u6bcf\u6267\u884c\u4e00\u6761SQL\u540e\u5199\u5165\u5230\u65e5\u5fd7\u5e76\u540c\u6b65\u5230\u78c1\u76d8\uff0cI\/O\u5f00\u9500\u5927\uff0c\u6267\u884c\u5b8cSQL\u8981\u7b49\u5f85\u65e5\u5fd7\u8bfb\u5199\uff0c\u6548\u7387\u4f4e\u30022\u4ee3\u8868\u53ea\u628a\u65e5\u5fd7\u5199\u5165\u5230\u7cfb\u7edf\u7f13\u5b58\u533a\uff0c\u518d\u6bcf\u79d2\u540c\u6b65\u5230\u78c1\u76d8\uff0c\u6548\u7387\u5f88\u9ad8\uff0c\u5982\u679c\u670d\u52a1\u5668\u6545\u969c\uff0c\u624d\u4f1a\u4e22\u5931\u4e8b\u52a1\u6570\u636e\u3002\u5bf9\u6570\u636e\u5b89\u5168\u6027\u8981\u6c42\u4e0d\u662f\u5f88\u9ad8\u7684\u63a8\u8350\u8bbe\u7f6e2\uff0c\u6027\u80fd\u9ad8\uff0c\u4fee\u6539\u540e\u6548\u679c\u660e\u663e\u3002\r\ninnodb_file_per_table = OFF\r\n#\u9ed8\u8ba4\u662f\u5171\u4eab\u8868\u7a7a\u95f4\uff0c\u5171\u4eab\u8868\u7a7a\u95f4idbdata\u6587\u4ef6\u4e0d\u65ad\u589e\u5927\uff0c\u5f71\u54cd\u4e00\u5b9a\u7684I\/O\u6027\u80fd\u3002\u63a8\u8350\u5f00\u542f\u72ec\u7acb\u8868\u7a7a\u95f4\u6a21\u5f0f\uff0c\u6bcf\u4e2a\u8868\u7684\u7d22\u5f15\u548c\u6570\u636e\u90fd\u5b58\u5728\u81ea\u5df1\u72ec\u7acb\u7684\u8868\u7a7a\u95f4\u4e2d\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5355\u8868\u5728\u4e0d\u540c\u6570\u636e\u5e93\u4e2d\u79fb\u52a8\u3002\r\ninnodb_log_buffer_size = 8M\r\n#\u65e5\u5fd7\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u7531\u4e8e\u65e5\u5fd7\u6700\u957f\u6bcf\u79d2\u949f\u5237\u65b0\u4e00\u6b21\uff0c\u6240\u4ee5\u4e00\u822c\u4e0d\u7528\u8d85\u8fc716M<\/span><\/pre>\n<h4>\n\t<span>3.2 \u7cfb\u7edf\u5185\u6838\u4f18\u5316<\/span><br \/>\n<\/h4>\n<p>\n\t<span>\u5927\u591a\u6570MySQL\u90fd\u90e8\u7f72\u5728linux\u7cfb\u7edf\u4e0a\uff0c\u6240\u4ee5\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e00\u4e9b\u53c2\u6570\u4e5f\u4f1a\u5f71\u54cd\u5230MySQL\u6027\u80fd\uff0c\u4ee5\u4e0b\u5bf9linux\u5185\u6838\u8fdb\u884c\u9002\u5f53\u4f18\u5316\u3002<\/span>\n<\/p>\n<h4>\n\t<span>3.3 \u786c\u4ef6\u914d\u7f6e<\/span><br \/>\n<\/h4>\n<p>\n\t<span>\u52a0\u5927\u7269\u7406\u5185\u5b58\uff0c\u63d0\u9ad8\u6587\u4ef6\u7cfb\u7edf\u6027\u80fd\u3002linux\u5185\u6838\u4f1a\u4ece\u5185\u5b58\u4e2d\u5206\u914d\u51fa\u7f13\u5b58\u533a\uff08\u7cfb\u7edf\u7f13\u5b58\u548c\u6570\u636e\u7f13\u5b58\uff09\u6765\u5b58\u653e\u70ed\u6570\u636e\uff0c\u901a\u8fc7\u6587\u4ef6\u7cfb\u7edf\u5ef6\u8fdf\u5199\u5165\u673a\u5236\uff0c\u7b49\u6ee1\u8db3\u6761\u4ef6\u65f6\uff08\u5982\u7f13\u5b58\u533a\u5927\u5c0f\u5230\u8fbe\u4e00\u5b9a\u767e\u5206\u6bd4\u6216\u8005\u6267\u884csync\u547d\u4ee4\uff09\u624d\u4f1a\u540c\u6b65\u5230\u78c1\u76d8\u3002\u4e5f\u5c31\u662f\u8bf4\u7269\u7406\u5185\u5b58\u8d8a\u5927\uff0c\u5206\u914d\u7f13\u5b58\u533a\u8d8a\u5927\uff0c\u7f13\u5b58\u6570\u636e\u8d8a\u591a\u3002\u5f53\u7136\uff0c\u670d\u52a1\u5668\u6545\u969c\u4f1a\u4e22\u5931\u4e00\u5b9a\u7684\u7f13\u5b58\u6570\u636e\u3002<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\tSSD\u786c\u76d8\u4ee3\u66ffSAS\u786c\u76d8\uff0c\u5c06RAID\u7ea7\u522b\u8c03\u6574\u4e3aRAID1+0\uff0c\u76f8\u5bf9\u4e8eRAID1\u548cRAID5\u6709\u66f4\u597d\u7684\u8bfb\u5199\u6027\u80fd\uff08IOPS\uff09\uff0c\u6bd5\u7adf\u6570\u636e\u5e93\u7684\u538b\u529b\u4e3b\u8981\u6765\u81ea\u78c1\u76d8I\/O\u65b9\u9762\u3002<\/span>\n<\/p>\n<h4>\n\t<span>4\u3001\u6570\u636e\u5e93\u67b6\u6784\u6269\u5c55<\/span><br \/>\n<\/h4>\n<p>\n\t<span>\u968f\u7740\u4e1a\u52a1\u91cf\u8d8a\u6765\u8d8a\u5927\uff0c\u5355\u53f0\u6570\u636e\u5e93\u670d\u52a1\u5668\u6027\u80fd\u5df2\u65e0\u6cd5\u6ee1\u8db3\u4e1a\u52a1\u9700\u6c42\uff0c\u8be5\u8003\u8651\u52a0\u673a\u5668\u4e86\uff0c\u8be5\u505a\u96c6\u7fa4\u4e86~~~\u3002\u4e3b\u8981\u601d\u60f3\u662f\u5206\u89e3\u5355\u53f0\u6570\u636e\u5e93\u8d1f\u8f7d\uff0c\u7a81\u7834\u78c1\u76d8I\/O\u6027\u80fd\uff0c\u70ed\u6570\u636e\u5b58\u653e\u7f13\u5b58\u4e2d\uff0c\u964d\u4f4e\u78c1\u76d8I\/O\u8bbf\u95ee\u9891\u7387\u3002<\/span>\n<\/p>\n<h5>\n\t<span>4.1 \u4e3b\u4ece\u590d\u5236\u4e0e\u8bfb\u5199\u5206\u79bb<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u56e0\u4e3a\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u6570\u636e\u5e93\u5927\u591a\u90fd\u662f\u8bfb\u64cd\u4f5c\uff0c\u6240\u4ee5\u90e8\u7f72\u4e00\u4e3b\u591a\u4ece\u67b6\u6784\uff0c\u4e3b\u6570\u636e\u5e93\u8d1f\u8d23\u5199\u64cd\u4f5c\uff0c\u5e76\u505a\u53cc\u51fb\u70ed\u5907\uff0c\u591a\u53f0\u4ece\u6570\u636e\u5e93\u505a\u8d1f\u8f7d\u5747\u8861\uff0c\u8d1f\u8d23\u8bfb\u64cd\u4f5c\uff0c\u4e3b\u6d41\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u6709LVS\u3001HAProxy\u3001Nginx\u3002\u600e\u4e48\u6765\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb\u5462\uff1f\u5927\u591a\u6570\u4f01\u4e1a\u662f\u5728\u4ee3\u7801\u5c42\u9762\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb\uff0c\u6548\u7387\u6bd4\u8f83\u9ad8\u3002\u53e6\u4e00\u4e2a\u79cd\u65b9\u5f0f\u901a\u8fc7\u4ee3\u7406\u7a0b\u5e8f\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb\uff0c\u4f01\u4e1a\u4e2d\u5e94\u7528\u8f83\u5c11\uff0c\u5e38\u89c1\u4ee3\u7406\u7a0b\u5e8f\u6709MySQL Proxy\u3001Amoeba\u3002\u5728\u8fd9\u6837\u6570\u636e\u5e93\u96c6\u7fa4\u67b6\u6784\u4e2d\uff0c\u5927\u5927\u589e\u52a0\u6570\u636e\u5e93\u9ad8\u5e76\u53d1\u80fd\u529b\uff0c\u89e3\u51b3\u5355\u53f0\u6027\u80fd\u74f6\u9888\u95ee\u9898\u3002\u5982\u679c\u4ece\u6570\u636e\u5e93\u4e00\u53f0\u4ece\u5e93\u80fd\u5904\u74062000 QPS\uff0c\u90a3\u4e485\u53f0\u5c31\u80fd\u5904\u74061w QPS\uff0c\u6570\u636e\u5e93\u6a2a\u5411\u6269\u5c55\u6027\u4e5f\u5f88\u5bb9\u6613\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u6709\u65f6\uff0c\u9762\u5bf9\u5927\u91cf\u5199\u64cd\u4f5c\u7684\u5e94\u7528\u65f6\uff0c\u5355\u53f0\u5199\u6027\u80fd\u8fbe\u4e0d\u5230\u4e1a\u52a1\u9700\u6c42\u3002\u5982\u679c\u505a\u53cc\u4e3b\uff0c\u5c31\u4f1a\u9047\u5230\u6570\u636e\u5e93\u6570\u636e\u4e0d\u4e00\u81f4\u73b0\u8c61\uff0c\u4ea7\u751f\u8fd9\u4e2a\u539f\u56e0\u662f\u5728\u5e94\u7528\u7a0b\u5e8f\u4e0d\u540c\u7684\u7528\u6237\u4f1a\u6709\u53ef\u80fd\u64cd\u4f5c\u4e24\u53f0\u6570\u636e\u5e93\uff0c\u540c\u65f6\u7684\u66f4\u65b0\u64cd\u4f5c\u9020\u6210\u4e24\u53f0\u6570\u636e\u5e93\u6570\u636e\u5e93\u6570\u636e\u53d1\u751f\u51b2\u7a81\u6216\u8005\u4e0d\u4e00\u81f4\u3002\u5728\u5355\u5e93\u65f6MySQL\u5229\u7528\u5b58\u50a8\u5f15\u64ce\u673a\u5236\u8868\u9501\u548c\u884c\u9501\u6765\u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u6027\uff0c\u600e\u6837\u5728\u591a\u53f0\u4e3b\u5e93\u65f6\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f\u6709\u4e00\u5957\u57fa\u4e8eperl\u8bed\u8a00\u5f00\u53d1\u7684\u4e3b\u4ece\u590d\u5236\u7ba1\u7406\u5de5\u5177\uff0c\u53ebMySQL-MMM\uff08Master-Master replication managerfor Mysql\uff0cMysql\u4e3b\u4e3b\u590d\u5236\u7ba1\u7406\u5668\uff09\uff0c\u8fd9\u4e2a\u5de5\u5177\u6700\u5927\u7684\u4f18\u70b9\u662f\u5728\u540c\u4e00\u65f6\u95f4\u53ea\u63d0\u4f9b\u4e00\u53f0\u6570\u636e\u5e93\u5199\u64cd\u4f5c\uff0c\u6709\u6548\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u3002<\/span>\n<\/p>\n<h5>\n\t<span>4.2 \u589e\u52a0\u7f13\u5b58<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u7ed9\u6570\u636e\u5e93\u589e\u52a0\u7f13\u5b58\u7cfb\u7edf\uff0c\u628a\u70ed\u6570\u636e\u7f13\u5b58\u5230\u5185\u5b58\u4e2d\uff0c\u5982\u679c\u5185\u5b58\u7f13\u5b58\u4e2d\u6709\u8981\u8bf7\u6c42\u7684\u6570\u636e\u5c31\u4e0d\u518d\u53bb\u6570\u636e\u5e93\u4e2d\u8fd4\u56de\u7ed3\u679c\uff0c\u63d0\u9ad8\u8bfb\u6027\u80fd\u3002\u7f13\u5b58\u5b9e\u73b0\u6709\u672c\u5730\u7f13\u5b58\u548c\u5206\u5e03\u5f0f\u7f13\u5b58\uff0c\u672c\u5730\u7f13\u5b58\u662f\u5c06\u6570\u636e\u7f13\u5b58\u5230\u672c\u5730\u670d\u52a1\u5668\u5185\u5b58\u4e2d\u6216\u8005\u6587\u4ef6\u4e2d\uff0c\u901f\u5ea6\u5feb\u3002\u5206\u5e03\u5f0f\u53ef\u4ee5\u7f13\u5b58\u6d77\u91cf\u6570\u636e\uff0c\u6269\u5c55\u5bb9\u6613\uff0c\u4e3b\u6d41\u7684\u5206\u5e03\u5f0f\u7f13\u5b58\u7cfb\u7edf\u6709memcached\u3001redis\uff0cmemcached\u6027\u80fd\u7a33\u5b9a\uff0c\u6570\u636e\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\uff0c\u901f\u5ea6\u5f88\u5feb\uff0cQPS\u53ef\u8fbe8w\u5de6\u53f3\u3002\u5982\u679c\u60f3\u6570\u636e\u6301\u4e45\u5316\u90a3\u5c31\u7528redis\uff0c\u6027\u80fd\u4e0d\u4f4e\u4e8ememcached\u3002<\/span>\n<\/p>\n<h5>\n\t<span>4.3 \u5206\u5e93<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u5206\u5e93\u662f\u6839\u636e\u4e1a\u52a1\u4e0d\u540c\u628a\u76f8\u5173\u7684\u8868\u5207\u5206\u5230\u4e0d\u540c\u7684\u6570\u636e\u5e93\u4e2d\uff0c\u6bd4\u5982web\u3001bbs\u3001blog\u7b49\u5e93\u3002\u5982\u679c\u4e1a\u52a1\u91cf\u5f88\u5927\uff0c\u8fd8\u53ef\u5c06\u5207\u5206\u540e\u7684\u5e93\u505a\u4e3b\u4ece\u67b6\u6784\uff0c\u8fdb\u4e00\u6b65\u907f\u514d\u5355\u4e2a\u5e93\u538b\u529b\u8fc7\u5927\u3002<\/span>\n<\/p>\n<h5>\n\t<span>4.4 \u5206\u8868<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u6570\u636e\u91cf\u7684\u65e5\u5267\u589e\u52a0\uff0c\u6570\u636e\u5e93\u4e2d\u67d0\u4e2a\u8868\u6709\u51e0\u767e\u4e07\u6761\u6570\u636e\uff0c\u5bfc\u81f4\u67e5\u8be2\u548c\u63d2\u5165\u8017\u65f6\u592a\u957f\uff0c\u600e\u4e48\u80fd\u89e3\u51b3\u5355\u8868\u538b\u529b\u5462\uff1f\u4f60\u5c31\u8be5\u8003\u8651\u662f\u5426\u628a\u8fd9\u4e2a\u8868\u62c6\u5206\u6210\u591a\u4e2a\u5c0f\u8868\uff0c\u6765\u51cf\u8f7b\u5355\u4e2a\u8868\u7684\u538b\u529b\uff0c\u63d0\u9ad8\u5904\u7406\u6548\u7387\uff0c\u6b64\u65b9\u5f0f\u79f0\u4e3a\u5206\u8868\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u5206\u8868\u6280\u672f\u6bd4\u8f83\u9ebb\u70e6\uff0c\u8981\u4fee\u6539\u7a0b\u5e8f\u4ee3\u7801\u91cc\u7684SQL\u8bed\u53e5\uff0c\u8fd8\u8981\u624b\u52a8\u53bb\u521b\u5efa\u5176\u4ed6\u8868\uff0c\u4e5f\u53ef\u4ee5\u7528merge\u5b58\u50a8\u5f15\u64ce\u5b9e\u73b0\u5206\u8868\uff0c\u76f8\u5bf9\u7b80\u5355\u8bb8\u591a\u3002\u5206\u8868\u540e\uff0c\u7a0b\u5e8f\u662f\u5bf9\u4e00\u4e2a\u603b\u8868\u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd9\u4e2a\u603b\u8868\u4e0d\u5b58\u653e\u6570\u636e\uff0c\u53ea\u6709\u4e00\u4e9b\u5206\u8868\u7684\u5173\u7cfb\uff0c\u4ee5\u53ca\u66f4\u65b0\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u603b\u8868\u4f1a\u6839\u636e\u4e0d\u540c\u7684\u67e5\u8be2\uff0c\u5c06\u538b\u529b\u5206\u5230\u4e0d\u540c\u7684\u5c0f\u8868\u4e0a\uff0c\u56e0\u6b64\u63d0\u9ad8\u5e76\u53d1\u80fd\u529b\u548c\u78c1\u76d8I\/O\u6027\u80fd\u3002<\/span>\n<\/p>\n<p>\n\t<span><strong style=\"margin: 0px;padding: 0px\">\u5206\u8868\u5206\u4e3a\u5782\u76f4\u62c6\u5206\u548c\u6c34\u5e73\u62c6\u5206\uff1a<\/strong><\/span>\n<\/p>\n<p>\n\t<span>\u5782\u76f4\u62c6\u5206\uff1a\u628a\u539f\u6765\u7684\u4e00\u4e2a\u5f88\u591a\u5b57\u6bb5\u7684\u8868\u62c6\u5206\u591a\u4e2a\u8868\uff0c\u89e3\u51b3\u8868\u7684\u5bbd\u5ea6\u95ee\u9898\u3002\u4f60\u53ef\u4ee5\u628a\u4e0d\u5e38\u7528\u7684\u5b57\u6bb5\u5355\u72ec\u653e\u5230\u4e00\u4e2a\u8868\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u628a\u5927\u5b57\u6bb5\u72ec\u7acb\u653e\u4e00\u4e2a\u8868\u4e2d\uff0c\u6216\u8005\u628a\u5173\u8054\u5bc6\u5207\u7684\u5b57\u6bb5\u653e\u4e00\u4e2a\u8868\u4e2d\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u6c34\u5e73\u62c6\u5206\uff1a\u628a\u539f\u6765\u4e00\u4e2a\u8868\u62c6\u5206\u6210\u591a\u4e2a\u8868\uff0c\u6bcf\u4e2a\u8868\u7684\u7ed3\u6784\u90fd\u4e00\u6837\uff0c\u89e3\u51b3\u5355\u8868\u6570\u636e\u91cf\u5927\u7684\u95ee\u9898\u3002<\/span>\n<\/p>\n<h5>\n\t<span>4.5 \u5206\u533a<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u5206\u533a\u5c31\u662f\u628a\u4e00\u5f20\u8868\u7684\u6570\u636e\u5206\u6210\u591a\u4e2a\u533a\u5757\uff0c\u8fd9\u4e9b\u533a\u5757\u53ef\u4ee5\u5728\u4e00\u4e2a\u78c1\u76d8\u4e0a\uff0c\u4e5f\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u78c1\u76d8\u4e0a\uff0c\u5206\u533a\u540e\uff0c\u8868\u9762\u4e0a\u8fd8\u662f\u4e00\u5f20\u8868\uff0c\u4f46\u6570\u636e\u6563\u5217\u5728\u591a\u4e2a\u4f4d\u7f6e\uff0c\u8fd9\u6837\u4e00\u6765\uff0c\u591a\u5757\u786c\u76d8\u540c\u65f6\u5904\u7406\u4e0d\u540c\u7684\u8bf7\u6c42\uff0c\u4ece\u800c\u63d0\u9ad8\u78c1\u76d8I\/O\u8bfb\u5199\u6027\u80fd\uff0c\u5b9e\u73b0\u6bd4\u8f83\u7b80\u5355\u3002<\/span>\n<\/p>\n<p>\n\t<span>\u6ce8\uff1a\u589e\u52a0\u7f13\u5b58\u3001\u5206\u5e93\u3001\u5206\u8868\u548c\u5206\u533a\u4e3b\u8981\u7531\u7a0b\u5e8f\u733f\u6765\u5b9e\u73b0\u3002<\/span>\n<\/p>\n<h4>\n\t<span>5\u3001\u6570\u636e\u5e93\u7ef4\u62a4<\/span><br \/>\n<\/h4>\n<p>\n\t<span>\u6570\u636e\u5e93\u7ef4\u62a4\u662f\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u6216\u8005DBA\u4e3b\u8981\u5de5\u4f5c\uff0c\u5305\u62ec\u6027\u80fd\u76d1\u63a7\u3001\u6027\u80fd\u5206\u6790\u3001\u6027\u80fd\u8c03\u4f18\u3001\u6570\u636e\u5e93\u5907\u4efd\u548c\u6062\u590d\u7b49\u3002<\/span>\n<\/p>\n<h5>\n\t<span>5.1 \u6027\u80fd\u72b6\u6001\u5173\u952e\u6307\u6807<\/span><br \/>\n<\/h5>\n<ul>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>QPS\uff0cQueries Per Second\uff1a\u6bcf\u79d2\u67e5\u8be2\u6570\uff0c\u4e00\u53f0\u6570\u636e\u5e93\u6bcf\u79d2\u80fd\u591f\u5904\u7406\u7684\u67e5\u8be2\u6b21\u6570\uff1b<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>TPS\uff0cTransactions Per Second\uff1a\u6bcf\u79d2\u5904\u7406\u4e8b\u52a1\u6570\u3002<\/span>\n\t\t<\/p>\n<\/li>\n<\/ul>\n<p>\n\t<span>\u901a\u8fc7show status\u67e5\u770b\u8fd0\u884c\u72b6\u6001\uff0c\u4f1a\u6709300\u591a\u6761\u72b6\u6001\u4fe1\u606f\u8bb0\u5f55\uff0c\u5176\u4e2d\u6709\u51e0\u4e2a\u503c\u5e2e\u53ef\u4ee5\u6211\u4eec\u8ba1\u7b97\u51faQPS\u548cTPS\uff0c\u5982\u4e0b\uff1a<\/span>\n<\/p>\n<ul>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Uptime\uff1a\u670d\u52a1\u5668\u5df2\u7ecf\u8fd0\u884c\u7684\u5b9e\u9645\uff0c\u5355\u4f4d\u79d2<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Questions\uff1a\u5df2\u7ecf\u53d1\u9001\u7ed9\u6570\u636e\u5e93\u67e5\u8be2\u6570<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Com_select\uff1a\u67e5\u8be2\u6b21\u6570\uff0c\u5b9e\u9645\u64cd\u4f5c\u6570\u636e\u5e93\u7684<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Com_insert\uff1a\u63d2\u5165\u6b21\u6570<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Com_delete\uff1a\u5220\u9664\u6b21\u6570<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Com_update\uff1a\u66f4\u65b0\u6b21\u6570<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Com_commit\uff1a\u4e8b\u52a1\u6b21\u6570<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>Com_rollback\uff1a\u56de\u6eda\u6b21\u6570<\/span>\n\t\t<\/p>\n<\/li>\n<\/ul>\n<p>\n\t<span>\u90a3\u4e48\uff0c\u8ba1\u7b97\u65b9\u6cd5\u6765\u4e86\uff0c\u57fa\u4e8eQuestions\u8ba1\u7b97\u51faQPS\uff1a<\/span>\n<\/p>\n<p>\n\t<span>QPS = Questions \/ Uptime<\/span>\n<\/p>\n<pre>\r\n<span>mysql&gt; show global status like &#39;Questions&#39;;\r\nmysql&gt; show global status like &#39;Uptime&#39;;<\/span><\/pre>\n<p>\n\t<span>\u57fa\u4e8eCom_commit\u548cCom_rollback\u8ba1\u7b97\u51faTPS\uff1a<\/span>\n<\/p>\n<pre>\r\n<span>mysql&gt; show global status like &#39;Com_commit&#39;;\r\nmysql&gt; show global status like &#39;Com_rollback&#39;;\r\nmysql&gt; show global status like &#39;Uptime&#39;;\r\nTPS = (Com_commit + Com_rollback) \/ Uptime <\/span><\/pre>\n<p>\n\t<span>\u53e6\u4e00\u8ba1\u7b97\u65b9\u5f0f\uff1a\u57fa\u4e8eCom_select\u3001Com_insert\u3001Com_delete\u3001Com_update\u8ba1\u7b97\u51faQPS\u3002<\/span>\n<\/p>\n<pre>\r\n<span>mysql&gt;mysql&gt; show global status where Variable_name in(&#39;com_select&#39;,&#39;com_insert&#39;,&#39;com_delete&#39;,&#39;com_update&#39;);\r\n\u7b49\u5f851\u79d2\u518d\u6267\u884c\uff0c\u83b7\u53d6\u95f4\u9694\u5dee\u503c\uff0c\u7b2c\u4e8c\u6b21\u6bcf\u4e2a\u53d8\u91cf\u503c\u51cf\u53bb\u7b2c\u4e00\u6b21\u5bf9\u5e94\u7684\u53d8\u91cf\u503c\uff0c\u5c31\u662fQPS<\/span><\/pre>\n<p>\n\t<span>TPS\u8ba1\u7b97\u65b9\u6cd5\uff1a<\/span>\n<\/p>\n<pre>\r\n<span>mysql&gt;mysql&gt; show global status where Variable_name in(&#39;com_insert&#39;,&#39;com_delete&#39;,&#39;com_update&#39;);\r\n\u8ba1\u7b97TPS\uff0c\u5c31\u4e0d\u7b97\u67e5\u8be2\u64cd\u4f5c\u4e86\uff0c\u8ba1\u7b97\u51fa\u63d2\u5165\u3001\u5220\u9664\u3001\u66f4\u65b0\u56db\u4e2a\u503c\u5373\u53ef\u3002\r\n\u7ecf\u7f51\u53cb\u5bf9\u8fd9\u4e24\u4e2a\u8ba1\u7b97\u65b9\u5f0f\u7684\u6d4b\u8bd5\u5f97\u51fa\uff0c\u5f53\u6570\u636e\u5e93\u4e2dmyisam\u8868\u6bd4\u8f83\u591a\u65f6\uff0c\u4f7f\u7528Questions\u8ba1\u7b97\u6bd4\u8f83\u51c6\u786e\u3002\u5f53\u6570\u636e\u5e93\u4e2dinnodb\u8868\u6bd4\u8f83\u591a\u65f6\uff0c\u5219\u4ee5Com_*\u8ba1\u7b97\u6bd4\u8f83\u51c6\u786e\u3002<\/span><\/pre>\n<h5>\n\t<span>5.2 \u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7<\/span><br \/>\n<\/h5>\n<p>\n\t<span>MySQL\u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7\uff0c\u5206\u6790\u51fa\u54ea\u6761SQL\u8bed\u53e5\u6bd4\u8f83\u6162\uff0c\u4f7f\u7528set\u8bbe\u7f6e\u53d8\u91cf\uff0c\u91cd\u542f\u670d\u52a1\u5931\u6548\uff0c\u53ef\u4ee5\u5728my.cnf\u6dfb\u52a0\u53c2\u6570\u6c38\u4e45\u751f\u6548\u3002<\/span>\n<\/p>\n<pre>\r\n<span>mysql&gt; set global slow-query-log=on #\u5f00\u542f\u6162\u67e5\u8be2\u529f\u80fd\r\nmysql&gt; set global slow_query_log_file=&#39;\/var\/log\/mysql\/mysql-slow.log&#39;; #\u6307\u5b9a\u6162\u67e5\u8be2\u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e\r\nmysql&gt; set global log_queries_not_using_indexes=on; #\u8bb0\u5f55\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\u7684\u67e5\u8be2\r\nmysql&gt; set global long_query_time=1; #\u53ea\u8bb0\u5f55\u5904\u7406\u65f6\u95f41s\u4ee5\u4e0a\u7684\u6162\u67e5\u8be2<\/span><\/pre>\n<p>\n\t<span>\u5206\u6790\u6162\u67e5\u8be2\u65e5\u5fd7\uff0c\u53ef\u4ee5\u4f7f\u7528MySQL\u81ea\u5e26\u7684mysqldumpslow\u5de5\u5177\uff0c\u5206\u6790\u7684\u65e5\u5fd7\u8f83\u4e3a\u7b80\u5355\u3002<\/span>\n<\/p>\n<pre>\r\n<span> # mysqldumpslow -t 3 \/var\/log\/mysql\/mysql-slow.log #\u67e5\u770b\u6700\u6162\u7684\u524d\u4e09\u4e2a\u67e5\u8be2<\/span><\/pre>\n<p>\n\t<span>\u4e5f\u53ef\u4ee5\u4f7f\u7528percona\u516c\u53f8\u7684pt-query-digest\u5de5\u5177\uff0c\u65e5\u5fd7\u5206\u6790\u529f\u80fd\u5168\u9762\uff0c\u53ef\u5206\u6790slow log\u3001binlog\u3001general log\u3002<\/span>\n<\/p>\n<ul>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>\u5206\u6790\u6162\u67e5\u8be2\u65e5\u5fd7\uff1apt-query-digest \/var\/log\/mysql\/mysql-slow.log<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>\u5206\u6790binlog\u65e5\u5fd7\uff1amysqlbinlog mysql-bin.000001 &gt;mysql-bin.000001.sql<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>pt-query-digest &ndash;type=binlog mysql-bin.000001.sql<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>\u5206\u6790\u666e\u901a\u65e5\u5fd7\uff1apt-query-digest &ndash;type=genlog localhost.log<\/span>\n\t\t<\/p>\n<\/li>\n<\/ul>\n<h5>\n\t<span>5.3 \u6570\u636e\u5e93\u5907\u4efd<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u5907\u4efd\u6570\u636e\u5e93\u662f\u6700\u57fa\u672c\u7684\u5de5\u4f5c\uff0c\u4e5f\u662f\u6700\u91cd\u8981\u7684\uff0c\u5426\u5219\u540e\u679c\u5f88\u4e25\u91cd\uff0c\u4f60\u61c2\u5f97\uff01\u4f46\u7531\u4e8e\u6570\u636e\u5e93\u6bd4\u8f83\u5927\uff0c\u4e0a\u767eG\uff0c\u5f80\u5f80\u5907\u4efd\u90fd\u5f88\u8017\u8d39\u65f6\u95f4\uff0c\u6240\u4ee5\u5c31\u8be5\u9009\u62e9\u4e00\u4e2a\u6548\u7387\u9ad8\u7684\u5907\u4efd\u7b56\u7565\uff0c\u5bf9\u4e8e\u6570\u636e\u91cf\u5927\u7684\u6570\u636e\u5e93\uff0c\u4e00\u822c\u90fd\u91c7\u7528\u589e\u91cf\u5907\u4efd\u3002\u5e38\u7528\u7684\u5907\u4efd\u5de5\u5177\u6709mysqldump\u3001mysqlhotcopy\u3001xtrabackup\u7b49\uff0cmysqldump\u6bd4\u8f83\u9002\u7528\u4e8e\u5c0f\u7684\u6570\u636e\u5e93\uff0c\u56e0\u4e3a\u662f\u903b\u8f91\u5907\u4efd\uff0c\u6240\u4ee5\u5907\u4efd\u548c\u6062\u590d\u8017\u65f6\u90fd\u6bd4\u8f83\u957f\u3002mysqlhotcopy\u548cxtrabackup\u662f\u7269\u7406\u5907\u4efd\uff0c\u5907\u4efd\u548c\u6062\u590d\u901f\u5ea6\u5feb\uff0c\u4e0d\u5f71\u54cd\u6570\u636e\u5e93\u670d\u52a1\u60c5\u51b5\u4e0b\u8fdb\u884c\u70ed\u62f7\u8d1d\uff0c\u5efa\u8bae\u4f7f\u7528xtrabackup\uff0c\u652f\u6301\u589e\u91cf\u5907\u4efd\u3002<\/span>\n<\/p>\n<p>\n\t<span>Xtrabackup\u5907\u4efd\u5de5\u5177\u4f7f\u7528\u535a\u6587\uff1a<\/span><span>http:\/\/lizhenliang.blog.51cto.com\/7876557\/1612800<\/span>\n<\/p>\n<h5>\n\t<span>5.4 \u6570\u636e\u5e93\u4fee\u590d<\/span><br \/>\n<\/h5>\n<p>\n\t<span>\u6709\u65f6\u5019MySQL\u670d\u52a1\u5668\u7a81\u7136\u65ad\u7535\u3001\u5f02\u5e38\u5173\u95ed\uff0c\u4f1a\u5bfc\u81f4\u8868\u635f\u574f\uff0c\u65e0\u6cd5\u8bfb\u53d6\u8868\u6570\u636e\u3002\u8fd9\u65f6\u5c31\u53ef\u4ee5\u7528\u5230MySQL\u81ea\u5e26\u7684\u4e24\u4e2a\u5de5\u5177\u8fdb\u884c\u4fee\u590d\uff0cmyisamchk\u548cmysqlcheck\u3002<\/span>\n<\/p>\n<p>\n\t<span>myisamchk\uff1a\u53ea\u80fd\u4fee\u590dmyisam\u8868\uff0c\u9700\u8981\u505c\u6b62\u6570\u636e\u5e93<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t\u5e38\u7528\u53c2\u6570\uff1a<\/span>\n<\/p>\n<p>\n\t<span>-f &ndash;force \u5f3a\u5236\u4fee\u590d\uff0c\u8986\u76d6\u8001\u7684\u4e34\u65f6\u6587\u4ef6\uff0c\u4e00\u822c\u4e0d\u4f7f\u7528<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t-r &ndash;recover \u6062\u590d\u6a21\u5f0f<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t-q &ndash;quik \u5feb\u901f\u6062\u590d<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t-a &ndash;analyze \u5206\u6790\u8868<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t-o &ndash;safe-recover \u8001\u7684\u6062\u590d\u6a21\u5f0f\uff0c\u5982\u679c-r\u65e0\u6cd5\u4fee\u590d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b64\u53c2\u6570\u8bd5\u8bd5<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t-F &ndash;fast \u53ea\u68c0\u67e5\u6ca1\u6709\u6b63\u5e38\u5173\u95ed\u7684\u8868<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t\u5feb\u901f\u4fee\u590dweibo\u6570\u636e\u5e93:<\/span>\n<\/p>\n<pre>\r\n<span># cd \/var\/lib\/mysql\/weibo \r\n# myisamchk -r -q *.MYI<\/span><\/pre>\n<p>\n\t<span>mysqlcheck\uff1amyisam\u548cinnodb\u8868\u90fd\u53ef\u4ee5\u7528\uff0c\u4e0d\u9700\u8981\u505c\u6b62\u6570\u636e\u5e93\uff0c\u5982\u4fee\u590d\u5355\u4e2a\u8868\uff0c\u53ef\u5728\u6570\u636e\u5e93\u540e\u9762\u6dfb\u52a0\u8868\u540d\uff0c\u4ee5\u7a7a\u683c\u5206\u5272\u3002<br style=\"margin: 0px;padding: 0px\" \/><br \/>\n\t<br \/>\n\t\u5e38\u7528\u53c2\u6570\uff1a<\/span>\n<\/p>\n<ul>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-a &ndash;all-databases \u68c0\u67e5\u6240\u6709\u7684\u5e93<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-r &ndash;repair \u4fee\u590d\u8868<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-c &ndash;check \u68c0\u67e5\u8868\uff0c\u9ed8\u8ba4\u9009\u9879<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-a &ndash;analyze \u5206\u6790\u8868<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-o &ndash;optimize \u4f18\u5316\u8868<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-q &ndash;quik \u6700\u5feb\u68c0\u67e5\u6216\u4fee\u590d\u8868<\/span>\n\t\t<\/p>\n<\/li>\n<li style=\"margin: 0px;padding: 0px\">\n<p style=\"margin: 0px;padding: 0px;clear: both;line-height: 1.5em\">\n\t\t\t<span>-F &ndash;fast \u53ea\u68c0\u67e5\u6ca1\u6709\u6b63\u5e38\u5173\u95ed\u7684\u8868<\/span>\n\t\t<\/p>\n<\/li>\n<\/ul>\n<p>\n\t<span>\u5feb\u901f\u4fee\u590dweibo\u6570\u636e\u5e93:<\/span>\n<\/p>\n<p>\n\t<span>mysqlcheck -r -q -uroot -p123 weibo<\/span>\n<\/p>\n<h5>\n\t<span>5.5 \u53e6\u5916\uff0c\u67e5\u770bCPU\u548cI\/O\u6027\u80fd\u65b9\u6cd5<\/span><span style=\"font-size: 13px; line-height: 1.6;\">\u53c2\u6570-m\u662f\u4ee5M\u5355\u4f4d\u663e\u793a\uff0c\u9ed8\u8ba4K<\/span><br \/>\n<\/h5>\n<p>\n\t<span>%util\uff1a\u5f53\u8fbe\u5230100%\u65f6\uff0c\u8bf4\u660eI\/O\u5f88\u5fd9\u3002<\/span>\n<\/p>\n<p>\n\t<span>await\uff1a\u8bf7\u6c42\u5728\u961f\u5217\u4e2d\u7b49\u5f85\u65f6\u95f4\uff0c\u76f4\u63a5\u5f71\u54cdread\u65f6\u95f4\u3002<\/span>\n<\/p>\n<p>\n\t<span>I\/O\u6781\u9650\uff1aIOPS\uff08r\/s+w\/s\uff09,\u4e00\u822c\u57281200\u5de6\u53f3\u3002\uff08IOPS\uff0c\u6bcf\u79d2\u8fdb\u884c\u8bfb\u5199\uff08I\/O\uff09\u64cd\u4f5c\u6b21\u6570\uff09<\/span>\n<\/p>\n<p>\n\t<span>I\/O\u5e26\u5bbd\uff1a\u5728\u987a\u5e8f\u8bfb\u5199\u6a21\u5f0f\u4e0bSAS\u786c\u76d8\u7406\u8bba\u503c\u5728300M\/s\u5de6\u53f3\uff0cSSD\u786c\u76d8\u7406\u8bba\u503c\u5728600M\/s\u5de6\u53f3\u3002<\/span><\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=173\">MySQL\u6570\u636e\u5e93\u53d1\u5c55\u5468\u671f\u4e2d\u6240\u9762\u4e34\u7684\u95ee\u9898\u53ca\u4f18\u5316\u65b9\u6848<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea\uff1a\u7a0b\u5e8f\u5458\u65e5\u5fd7 http:\/\/mp.weixin.qq.com\/s?__biz=MzAxNjAzMTQyMA [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":156,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions\/175"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/media\/156"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}