{"id":1229,"date":"2018-03-29T15:21:29","date_gmt":"2018-03-29T15:21:29","guid":{"rendered":"https:\/\/peloo.net\/?p=1229"},"modified":"2018-04-02T11:54:32","modified_gmt":"2018-04-02T11:54:32","slug":"mysql%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e5%af%b9%e6%af%94%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/peloo.net\/?p=1229","title":{"rendered":"MySQL\u6027\u80fd\u4f18\u5316\u524d\u540e\u5bf9\u6bd4\u6d4b\u8bd5"},"content":{"rendered":"<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\"><strong>\u4e00\u3001MySQL\u4f18\u5316\u53c2\u6570\u8be6\u89e3<\/strong><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">1)&nbsp;&nbsp; \u8fde\u63a5\u8bf7\u6c42\u7684\u53d8\u91cf<br \/>\n\tMax_connections<br \/>\n\tMysql\u7684\u6700\u5927\u8fde\u63a5\u6570\uff0c\u5982\u679c\u670d\u52a1\u5668\u7684\u5e76\u53d1\u8bf7\u6c42\u91cf\u6bd4\u8f83\u5927\uff0c\u53ef\u4ee5\u8c03\u9ad8\u8fd9\u4e2a\u503c\uff0c\u5f53\u7136\u8fd9\u662f\u8981\u5efa\u7acb\u5728\u673a\u5668\u80fd\u591f\u652f\u6491\u7684\u60c5\u51b5\u4e0b\uff0c\u56e0\u4e3a\u5982\u679c\u8fde\u63a5\u6570\u8d8a\u6765\u8d8a\u591a\uff0cmysql\u4f1a\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u63d0\u4f9b\u7f13\u51b2\u533a\uff0c\u5c31\u4f1a\u5f00\u9500\u7684\u8d8a\u591a\u7684\u5185\u5b58\uff0c\u6240\u4ee5\u9700\u8981\u9002\u5f53\u7684\u8c03\u6574\u8be5\u503c\uff0c\u4e0d\u80fd\u968f\u4fbf\u53bb\u63d0\u9ad8\u8bbe\u503c\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u4fee\u6539\/etc\/my.cnf\u5728[mysqld]\u4e0b\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0c\u8bbe\u7f6e\u6700\u5927\u8fde\u63a5\u6570\u4e3a1024\uff0c\u91cd\u542fmysql\u670d\u52a1\u9a8c\u8bc1<br \/>\n\tvim\/etc\/my.cnf<br \/>\n\t\u6dfb\u52a0max_connections=1024<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">2\uff09back_log<br \/>\n\tmysql\u80fd\u6682\u5b58\u7684\u8fde\u63a5\u6570\u91cf\uff0c\u5f53\u4e3b\u8981mysql\u7ebf\u7a0b\u5728\u4e00\u4e2a\u5f88\u77ed\u65f6\u95f4\u5185\u5f97\u5230\u975e\u5e38\u591a\u7684\u8fde\u63a5\u8bf7\u6c42\u65f6\u5019\u5b83\u5c31\u4f1a\u8d77\u4f5c\u7528\uff0c\u5982\u679cmysql\u7684\u8fde\u63a5\u6570\u636e\u8fbe\u5230max_connections\u65f6\u5019\uff0c\u65b0\u6765\u7684\u8bf7\u6c42\u5c06\u4f1a\u88ab\u5b58\u5728\u5806\u6808\u4e2d\uff0c\u7b49\u5f85\u67d0\u4e00\u8fde\u63a5\u91ca\u653e\u8d44\u6e90\uff0c\u8be5\u63a8\u6808\u7684\u6570\u91cf\u53caback_log,\u5982\u679c\u7b49\u5f85\u8fde\u63a5\u7684\u6570\u91cf\u8d85\u8fc7back_log\uff0c\u5c06\u4e0d\u88ab\u6388\u4e88\u8fde\u63a5\u8d44\u6e90<br \/>\n\tback_log\u503c\u6307\u51fa\u5728mysql\u6682\u65f6\u505c\u6b62\u56de\u7b54\u65b0\u8bf7\u6c42\u4e4b\u524d\u7684\u77ed\u65f6\u95f4\u5185\u6709\u591a\u5c11\u4e2a\u8bf7\u6c42\u53ef\u4ee5\u88ab\u5b58\u5728\u63a8\u6808\u4e2d\uff0c\u53ea\u6709\u5982\u679c\u671f\u671b\u5728\u4e00\u4e2a\u77ed\u65f6\u95f4\u5185\u6709\u5f88\u591a\u8fde\u63a5\u7684\u65f6\u5019\u9700\u8981\u589e\u52a0\u5b83<br \/>\n\t\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770bback_log\u7684\u8bbe\u7f6e\u9ed8\u8ba4\u662f254<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7MySQL\u4e3b\u914d\u7f6e\u4fee\u6539\u5b83\u7684\u5927\u5c0f\uff0c\u8bbe\u7f6e\u6700\u5927\u8fde\u63a5\u6570\u4e3a\uff1a1024\u968f\u540e\u91cd\u542fMySQL\u670d\u52a1\u518d\u6b21\u67e5\u770b<br \/>\n\tvim \/etc\/my.cnf \u6dfb\u52a0\uff1aback_log=1024<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">3\uff09wait_timeout\u548cinteractive_timeout<br \/>\n\twait_timeout\uff1a\u6307\u7684\u662fmysql\u5728\u5173\u95ed\u4e00\u4e2a\u975e\u4ea4\u4e92\u7684\u8fde\u63a5\u4e4b\u524d\u6240\u8981\u7b49\u5f85\u7684\u79d2\u6570<br \/>\n\tinteractive_timeoutz\uff1a\u6307\u7684\u662fmysql\u5728\u5173\u95ed\u4e00\u4e2a\u4ea4\u4e92\u7684\u8fde\u63a5\u4e4b\u524d\u6240\u9700\u8981\u7b49\u5f85\u7684\u79d2\u6570\uff0c\u6bd4\u5982\u6211\u4eec\u5728\u7ec8\u7aef\u4e0a\u8fdb\u884cmysql\u7ba1\u7406\uff0c\u4f7f\u7528\u7684\u5373\u4f7f\u4ea4\u4e92\u7684\u8fde\u63a5\uff0c\u8fd9\u65f6\u5019\uff0c\u5982\u679c\u6ca1\u6709\u64cd\u4f5c\u7684\u65f6\u95f4\u8d85\u8fc7\u4e86interactive_time\u8bbe\u7f6e\u7684\u65f6\u95f4\u5c31\u4f1a\u81ea\u52a8\u7684\u65ad\u5f00\uff0c\u9ed8\u8ba4\u7684\u662f28800\uff0c\u53ef\u8c03\u4f18\u4e3a7200\u3002wait_timeout:\u5982\u679c\u8bbe\u7f6e\u592a\u5c0f\uff0c\u90a3\u4e48\u8fde\u63a5\u5173\u95ed\u7684\u5c31\u5f88\u5feb\uff0c\u4ece\u800c\u4f7f\u4e00\u4e9b\u6301\u4e45\u7684\u8fde\u63a5\u4e0d\u8d77\u4f5c\u7528<br \/>\n\t\u5982\u679c\u8bbe\u7f6e\u592a\u5927\uff0c\u5bb9\u6613\u9020\u6210\u8fde\u63a5\u6253\u5f00\u65f6\u95f4\u8fc7\u957f\uff0c\u5728show processlist\u65f6\u5019\uff0c\u80fd\u770b\u5230\u5f88\u591a\u7684\u8fde\u63a5 \u4e00\u822c\u5e0c\u671bwait_timeout\u5c3d\u53ef\u80fd\u4f4e<br \/>\n\t\u67e5\u770bwait_timeout\u548cinteractive_timeout\u7684\u8bbe\u7f6e<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u4fee\u6539\/etc\/my.cnf\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9<br \/>\n\twait_timeout=100<br \/>\n\tinteractive_timeout=100<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">4\uff09query_cache_size\uff08\u67e5\u8be2\u7f13\u5b58\u7b80\u79f0QC\uff09<br \/>\n\t\u4f7f\u7528\u67e5\u8be2\u7f13\u51b2\uff0cmysql\u5c06\u67e5\u8be2\u7ed3\u679c\u5b58\u653e\u5728\u7f13\u51b2\u533a\u4e2d\uff0c\u4eca\u540e\u5bf9\u4e8e\u540c\u6837\u7684select\u8bed\u53e5\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09,\u5c06\u76f4\u63a5\u4ece\u7f13\u51b2\u533a\u4e2d\u8bfb\u53d6\u7ed3\u679c\u3002<br \/>\n\t\u4e00\u4e2asql\u67e5\u8be2\u5982\u679c\u4ee5select\u5f00\u5934\uff0c\u90a3\u4e48mysql\u670d\u52a1\u5668\u5c06\u5c1d\u8bd5\u5bf9\u5176\u4f7f\u7528\u67e5\u8be2\u7f13\u5b58\u3002<br \/>\n\t\u6ce8\uff1a\u4e24\u4e2asql\u8bed\u53e5\uff0c\u53ea\u8981\u60f3\u5dee\u54ea\u6015\u662f\u4e00\u4e2a\u5b57\u7b26\uff08\u5217\u5982\u5927\u5c0f\u5199\u4e0d\u4e00\u6837\uff1b\u591a\u4e00\u4e2a\u7a7a\u683c\u7b49\uff09,\u90a3\u4e48\u8fd9\u4e24\u4e2asql\u5c06\u4f7f\u7528\u4e0d\u540c\u7684\u4e00\u4e2acache\u3002<br \/>\n\t\u4e0a\u8ff0\u72b6\u6001\u503c\u53ef\u4ee5\u4f7f\u7528show status like &#39;Qcache%\u83b7\u5f97&#39;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">Qcache_free_blocks\uff1a\u7f13\u5b58\u4e2d\u76f8\u90bb\u5185\u5b58\u5757\u7684\u4e2a\u6570\u3002\u5982\u679c\u8be5\u503c\u663e\u793a\u8f83\u5927\uff0c\u5219\u8bf4\u660eQuery Cache \u4e2d\u7684\u5185\u5b58\u788e\u7247\u8f83\u591a\u4e86\uff0cFLUSH QUERY CACHE\u4f1a\u5bf9\u7f13\u5b58\u4e2d\u7684\u788e\u7247\u8fdb\u884c\u6574\u7406\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u7a7a\u95f2\u5757\u3002<br \/>\n\t\u6ce8\uff1a\u5f53\u4e00\u4e2a\u8868\u88ab\u66f4\u65b0\u4e4b\u540e\uff0c\u548c\u5b83\u76f8\u5173\u7684cache blocks\u5c06\u88abfree\u3002\u4f46\u662f\u8fd9\u4e2ablock\u4f9d\u7136\u53ef\u80fd\u5b58\u5728\u961f\u5217\u4e2d\uff0c\u9664\u975e\u662f\u5728\u961f\u5217\u7684\u5c3e\u90e8\u3002\u53ef\u4ee5\u7528FLUSH QUERY CACHE\u8bed\u53e5\u6765\u6e05\u7a7afree blocks<br \/>\n\tQcache_free_memory\uff1aQuery Cache\u4e2d\u76ee\u524d\u5269\u4f59\u7684\u5185\u5b58\u5927\u5c0f\u3002\u901a\u8fc7\u8fd9\u4e2a\u53c2\u6570\u6211\u4eec\u53ef\u4ee5\u8f83\u4e3a\u51c6\u786e\u7684\u89c2\u5bdf\u51fa\u5f53\u524d\u7cfb\u7edf\u4e2d\u7684Query Cache\u5185\u5b58\u5927\u5c0f\u662f\u5426\u8db3\u591f\uff0c\u662f\u9700\u8981\u589e\u52a0\u8fd8\u662f\u8fc7\u591a\u4e86\u3002<br \/>\n\tQcache_hits\uff1a\u8868\u793a\u6709\u591a\u5c11\u6b21\u547d\u4e2d\u7f13\u5b58\u3002\u6211\u4eec\u4e3b\u8981\u53ef\u4ee5\u901a\u8fc7\u8be5\u503c\u6765\u9a8c\u8bc1\u6211\u4eec\u7684\u67e5\u8be2\u7f13\u5b58\u7684\u6548\u679c\u3002\u6570\u5b57\u8d8a\u5927\uff0c\u7f13\u5b58\u6548\u679c\u8d8a\u7406\u60f3\u3002<br \/>\n\tQcache_inserts\uff1a\u8868\u793a\u591a\u5c11\u6b21\u672a\u547d\u4e2d\u7136\u540e\u63d2\u5165\uff0c\u610f\u601d\u662f\u65b0\u6765\u7684SQL\u8bf7\u6c42\u5728\u7f13\u5b58\u4e2d\u672a\u627e\u5230\uff0c\u4e0d\u5f97\u4e0d\u6267\u884c\u67e5\u8be2\u5904\u7406\uff0c\u6267\u884c\u67e5\u8be2\u5904\u7406\u540e\u628a\u7ed3\u679cinsert\u5230\u67e5\u8be2\u7f13\u5b58\u4e2d\u3002\u8fd9\u6837\u7684\u60c5\u51b5\u7684\u6b21\u6570\u8d8a\u591a\uff0c\u8868\u793a\u67e5\u8be2\u7f13\u5b58\u5e94\u7528\u5230\u7684\u6bd4\u8f83\u5c11\uff0c\u6548\u679c\u4e5f\u5c31\u4e0d\u7406\u60f3\u3002\u5f53\u7136\u7cfb\u7edf\u521a\u542f\u52a8\u540e\uff0c\u67e5\u8be2\u7f13\u5b58\u662f\u7a7a\u7684\uff0c\u8fd9\u5f88\u6b63\u5e38\u3002<br \/>\n\tQcache_lowmem_prunes\uff1a\u591a\u5c11\u6761Query\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3\u800c\u88ab\u6e05\u9664\u51faQuery Cache\u3002\u901a\u8fc7&ldquo;Qcache_lowmem_prunes&rdquo;\u548c&ldquo;Qcache_free_memory&rdquo;\u76f8\u4e92\u7ed3\u5408\uff0c\u80fd\u591f\u66f4\u6e05\u695a\u7684\u4e86\u89e3\u5230\u6211\u4eec\u7cfb\u7edf\u4e2dQuery Cache \u7684\u5185\u5b58\u5927\u5c0f\u662f\u5426\u771f\u7684\u8db3\u591f\uff0c\u662f\u5426\u975e\u5e38\u9891\u7e41\u7684\u51fa\u73b0\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3\u800c\u6709Query\u88ab\u6362\u51fa\u3002\u8fd9\u4e2a\u6570\u5b57\u6700\u597d\u957f\u65f6\u95f4\u6765\u770b\uff1b\u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u5728\u4e0d\u65ad\u589e\u957f\uff0c\u5c31\u8868\u793a\u53ef\u80fd\u788e\u7247\u975e\u5e38\u4e25\u91cd\uff0c\u6216\u8005\u5185\u5b58\u5f88\u5c11\u3002\uff08\u4e0a\u9762\u7684free_blocks\u548cfree_memory\u53ef\u4ee5\u544a\u8bc9\u60a8\u5c5e\u4e8e\u54ea\u79cd\u60c5\u51b5\uff09<br \/>\n\tQcache_not_cached\uff1a\u4e0d\u9002\u5408\u8fdb\u884c\u7f13\u5b58\u7684\u67e5\u8be2\u7684\u6570\u91cf\uff0c\u901a\u5e38\u662f\u7531\u4e8e\u8fd9\u4e9b\u67e5\u8be2\u4e0d\u662f SELECT\u8bed\u53e5\u6216\u8005\u7528\u4e86now()\u4e4b\u7c7b\u7684\u51fd\u6570\u3002<br \/>\n\tQcache_queries_in_cache\uff1a\u5f53\u524dQuery Cache\u4e2dcache\u7684Query\u6570\u91cf\uff1b<br \/>\n\tQcache_total_blocks\uff1a\u5f53\u524dQuery Cache\u4e2d\u7684block\u6570\u91cf\uff1b\u3002<br \/>\n\t\u6211\u4eec\u518d\u67e5\u8be2\u4e00\u4e0b\u670d\u52a1\u5668\u5173\u4e8equery_cache\u7684\u914d\u7f6e\uff1a<br \/>\n\tmysql&gt;show variables like &#39;%query%&#39;;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">query_cache_type\u4e3aoff\u8868\u793a\u4e0d\u7f13\u5b58\u4efb\u4f55\u67e5\u8be2<br \/>\n\t\u4fee\u6539\/etc\/my.cnf,\u914d\u7f6e\u5b8c\u540e\u7684\u90e8\u5206\u6587\u4ef6\u5982\u4e0b\uff1a<br \/>\n\tquery_cache_size=256M<br \/>\n\tquery_cache_type=1<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">6\uff09max_connect_errors\u662f\u4e00\u4e2amysql\u4e2d\u4e0e\u5b89\u5168\u6709\u5173\u7684\u8ba1\u6570\u5668\u503c\uff0c\u5b83\u8d1f\u8d23\u963b\u6b62\u8fc7\u591a\u5c1d\u8bd5\u5931\u8d25\u7684\u5ba2\u6237\u7aef\u4ee5\u9632\u6b62\u66b4\u529b\u7834\u89e3\u5bc6\u7801\u7b49\u60c5\u51b5\uff0c\u5f53\u8d85\u8fc7\u6307\u5b9a\u6b21\u6570\uff0cmysql\u670d\u52a1\u5668\u5c06\u7981\u6b62host\u7684\u8fde\u63a5\u8bf7\u6c42\uff0c\u76f4\u5230mysql\u670d\u52a1\u5668\u91cd\u542f\u6216\u901a\u8fc7flush hosts\u547d\u4ee4\u6e05\u7a7a\u6b64host\u7684\u76f8\u5173\u4fe1\u606f max_connect_errors\u7684\u503c\u4e0e\u6027\u80fd\u5e76\u65e0\u592a\u5927\u5173\u7cfb\u3002<br \/>\n\t\u4fee\u6539\/etc\/my.cnf\u6587\u4ef6\uff0c\u5728[mysqld]\u4e0b\u9762\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9<br \/>\n\tmax_connect_errors=20<br \/>\n\t\u4fee\u6539\u5b8c\u540e\u91cd\u542fmysql\u670d\u52a1<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">7\uff09sort_buffer_size<br \/>\n\t\u6bcf\u4e2a\u9700\u8981\u8fdb\u884c\u6392\u5e8f\u7684\u7ebf\u7a0b\u5206\u914d\u8be5\u5927\u5c0f\u7684\u4e00\u4e2a\u7f13\u51b2\u533a\u3002\u589e\u52a0\u8fd9\u503c\u52a0\u901fORDER BY \u6216GROUP BY\u64cd\u4f5c\uff0cSort_Buffer_Size\u5e76\u4e0d\u662f\u8d8a\u5927\u8d8a\u597d\uff0c\u7531\u4e8e\u662fconnection\u7ea7\u7684\u53c2\u6570\uff0c\u8fc7\u5927\u7684\u8bbe\u7f6e+\u9ad8\u5e76\u53d1\u53ef\u80fd\u4f1a\u8017\u5c3d\u7cfb\u7edf\u5185\u5b58\u8d44\u6e90\u3002\u5217\u5982\uff1a500\u4e2a\u8fde\u63a5\u5c06\u4f1a\u6d88\u8017500*sort_buffer_size\uff082M\uff09=1G\u5185\u5b58<br \/>\n\t\u4fee\u6539\/etc\/my.cnf\u6587\u4ef6\uff0c\u5728[mysqld]\u4e0b\u9762\u6dfb\u52a0\u5982\u4e0b\uff1a<br \/>\n\tsort_buffer_size=2M<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">8\uff09max_allowed_packet=32M<br \/>\n\tmysql\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u4f1a\u9650\u5236\uff0cserver\u63a5\u53d7\u7684\u6570\u636e\u5305\u5927\u5c0f\u3002\u6709\u65f6\u5019\u5927\u7684\u63d2\u5165\u548c\u66f4\u65b0\u4f1a\u53d7max_allowed_packet\u53c2\u6570\u9650\u5236\uff0c\u5bfc\u81f4\u5199\u5165\u6216\u8005\u66f4\u65b0\u5931\u8d25\uff0c\u66f4\u5927\u503c\u662f1GB\uff0c\u5fc5\u987b\u8bbe\u7f6e1024\u7684\u500d\u6570<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">9\uff09join_buffer_size=2M<br \/>\n\t\u7528\u4e8e\u8868\u95f4\u5173\u8054\u7f13\u5b58\u7684\u5927\u5c0f\uff0c\u548csort_buffer_size\u4e00\u6837\uff0c\u8be5\u53c2\u6570\u5bf9\u5e94\u7684\u5206\u914d\u5185\u5b58\u4e5f\u662f\u6bcf\u4e2a\u8fde\u63a5\u72ec\u4eab\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">10\uff09thread_cache_size = 300&nbsp; &nbsp;<br \/>\n\t\u670d\u52a1\u5668\u7ebf\u7a0b\u7f13\u5b58\uff0c\u8fd9\u4e2a\u503c\u8868\u793a\u53ef\u4ee5\u91cd\u65b0\u5229\u7528\u4fdd\u5b58\u5728\u7f13\u5b58\u4e2d\u7ebf\u7a0b\u7684\u6570\u91cf,\u5f53\u65ad\u5f00\u8fde\u63a5\u65f6,\u90a3\u4e48\u5ba2\u6237\u7aef\u7684\u7ebf\u7a0b\u5c06\u88ab\u653e\u5230\u7f13\u5b58\u4e2d\u4ee5\u54cd\u5e94\u4e0b\u4e00\u4e2a\u5ba2\u6237\u800c\u4e0d\u662f\u9500\u6bc1(\u524d\u63d0\u662f\u7f13\u5b58\u6570\u672a\u8fbe\u4e0a\u9650),\u5982\u679c\u7ebf\u7a0b\u91cd\u65b0\u88ab\u8bf7\u6c42\uff0c\u90a3\u4e48\u8bf7\u6c42\u5c06\u4ece\u7f13\u5b58\u4e2d\u8bfb\u53d6,\u5982\u679c\u7f13\u5b58\u4e2d\u662f\u7a7a\u7684\u6216\u8005\u662f\u65b0\u7684\u8bf7\u6c42\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7ebf\u7a0b\u5c06\u88ab\u91cd\u65b0\u521b\u5efa,\u5982\u679c\u6709\u5f88\u591a\u65b0\u7684\u7ebf\u7a0b\uff0c\u589e\u52a0\u8fd9\u4e2a\u503c\u53ef\u4ee5\u6539\u5584\u7cfb\u7edf\u6027\u80fd.\u901a\u8fc7\u6bd4\u8f83 Connections \u548c Threads_created \u72b6\u6001\u7684\u53d8\u91cf\uff0c\u53ef\u4ee5\u770b\u5230\u8fd9\u4e2a\u53d8\u91cf\u7684\u4f5c\u7528\u3002\u8bbe\u7f6e\u89c4\u5219\u5982\u4e0b\uff1a1GB \u5185\u5b58\u914d\u7f6e\u4e3a8\uff0c2GB\u914d\u7f6e\u4e3a16\uff0c3GB\u914d\u7f6e\u4e3a32\uff0c4GB\u6216\u66f4\u9ad8\u5185\u5b58\uff0c\u53ef\u914d\u7f6e\u66f4\u5927\u3002\u670d\u52a1\u5668\u5904\u7406\u6b64\u5ba2\u6237\u7684\u7ebf\u7a0b\u5c06\u4f1a\u7f13\u5b58\u8d77\u6765\u4ee5\u54cd\u5e94\u4e0b\u4e00\u4e2a\u5ba2\u6237\u800c\u4e0d\u662f\u9500\u6bc1(\u524d\u63d0\u662f\u7f13\u5b58\u6570\u672a\u8fbe\u4e0a\u9650)<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">11.innodb_buffer_pool_size<br \/>\n\t\u5bf9\u4e8eInnoDB\u8868\u6765\u8bf4\uff0cinnodb_buffer_pool_size\u7684\u4f5c\u7528\u5c31\u76f8\u5f53\u4e8ekey_buffer_size\u5bf9\u4e8eMyISAM\u8868\u7684\u4f5c\u7528\u4e00\u6837\u3002InnoDB\u4f7f\u7528\u8be5\u53c2\u6570\u6307\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u6765\u7f13\u51b2\u6570\u636e\u548c\u7d22\u5f15\u3002\u5bf9\u4e8e\u5355\u72ec\u7684MySQL\u6570\u636e\u5e93\u670d\u52a1\u5668\uff0c\u6700\u5927\u53ef\u4ee5\u628a\u8be5\u503c\u8bbe\u7f6e\u6210\u7269\u7406\u5185\u5b58\u768480%\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">mysql&gt; show variables like&#39;innodb_buffer_pool_size&#39;;&nbsp; &nbsp;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u8bbe\u7f6einnodb_buffer_pool_size<br \/>\n\t\u4fee\u6539\/etc\/my.cnf\u6587\u4ef6\uff0c\u5728[mysqld]\u4e0b\u9762\u6839\u636e\u5b9e\u9645\u786c\u4ef6\u914d\u7f6e\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">innodb_buffer_pool_size= 2048M &nbsp;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u91cd\u542fMySQL Server\u8fdb\u5165\u540e\uff0c\u67e5\u770b\u8bbe\u7f6e\u5df2\u7ecf\u751f\u6548\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">12. innodb_flush_log_at_trx_commit<br \/>\n\t\u4e3b\u8981\u63a7\u5236\u4e86innodb\u5c06log buffer\u4e2d\u7684\u6570\u636e\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u5e76flush\u78c1\u76d8\u7684\u65f6\u95f4\u70b9\uff0c\u53d6\u503c\u5206\u522b\u4e3a0\u30011\u30012\u4e09\u4e2a\u30020\uff0c\u8868\u793a\u5f53\u4e8b\u52a1\u63d0\u4ea4\u65f6\uff0c\u4e0d\u505a\u65e5\u5fd7\u5199\u5165\u64cd\u4f5c\uff0c\u800c\u662f\u6bcf\u79d2\u949f\u5c06log buffer\u4e2d\u7684\u6570\u636e\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u5e76flush\u78c1\u76d8\u4e00\u6b21\uff1b1\uff0c\u5219\u5728\u6bcf\u79d2\u949f\u6216\u662f\u6bcf\u6b21\u4e8b\u7269\u7684\u63d0\u4ea4\u90fd\u4f1a\u5f15\u8d77\u65e5\u5fd7\u6587\u4ef6\u5199\u5165\u3001flush\u78c1\u76d8\u7684\u64cd\u4f5c\uff0c\u786e\u4fdd\u4e86\u4e8b\u52a1\u7684ACID\uff1b\u8bbe\u7f6e\u4e3a2\uff0c\u6bcf\u6b21\u4e8b\u52a1\u63d0\u4ea4\u5f15\u8d77\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u7684\u52a8\u4f5c\uff0c\u4f46\u6bcf\u79d2\u949f\u5b8c\u6210\u4e00\u6b21flush\u78c1\u76d8\u64cd\u4f5c\u3002<br \/>\n\t\u5b9e\u9645\u6d4b\u8bd5\u53d1\u73b0\uff0c\u8be5\u503c\u5bf9\u63d2\u5165\u6570\u636e\u7684\u901f\u5ea6\u5f71\u54cd\u975e\u5e38\u5927\uff0c\u8bbe\u7f6e\u4e3a2\u65f6\u63d2\u516510000\u6761\u8bb0\u5f55\u53ea\u9700\u89812\u79d2\uff0c\u8bbe\u7f6e\u4e3a0\u65f6\u53ea\u9700\u89811\u79d2\uff0c\u800c\u8bbe\u7f6e\u4e3a1\u65f6\u5219\u9700\u8981229\u79d2\u3002\u56e0\u6b64\uff0cMySQL\u624b\u518c\u4e5f\u5efa\u8bae\u5c3d\u91cf\u5c06\u63d2\u5165\u64cd\u4f5c\u5408\u5e76\u6210\u4e00\u4e2a\u4e8b\u52a1\uff0c\u8fd9\u6837\u53ef\u4ee5\u5927\u5e45\u63d0\u9ad8\u901f\u5ea6\u3002<br \/>\n\t\u6839\u636eMySQL\u624b\u518c\uff0c\u5728\u5141\u8bb8\u4e22\u5931\u6700\u8fd1\u90e8\u5206\u4e8b\u52a1\u7684\u5371\u9669\u7684\u524d\u63d0\u4e0b\uff0c\u53ef\u4ee5\u628a\u8be5\u503c\u8bbe\u4e3a0\u62162\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">13.innodb_thread_concurrency = 0&nbsp; &nbsp;<br \/>\n\t\u6b64\u53c2\u6570\u7528\u6765\u8bbe\u7f6einnodb\u7ebf\u7a0b\u7684\u5e76\u53d1\u6570\u91cf\uff0c\u9ed8\u8ba4\u503c\u4e3a0\u8868\u793a\u4e0d\u9650\u5236\uff0c\u82e5\u8981\u8bbe\u7f6e\u5219\u4e0e\u670d\u52a1\u5668\u7684CPU\u6838\u6570\u76f8\u540c\u6216\u662fcpu\u7684\u6838\u6570\u76842\u500d\uff0c\u5efa\u8bae\u7528\u9ed8\u8ba4\u8bbe\u7f6e\uff0c\u4e00\u822c\u4e3a8.<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">14.innodb_log_buffer_size<br \/>\n\t\u6b64\u53c2\u6570\u786e\u5b9a\u4e9b\u65e5\u5fd7\u6587\u4ef6\u6240\u7528\u7684\u5185\u5b58\u5927\u5c0f\uff0c\u4ee5M\u4e3a\u5355\u4f4d\u3002\u7f13\u51b2\u533a\u66f4\u5927\u80fd\u63d0\u9ad8\u6027\u80fd\uff0c\u5bf9\u4e8e\u8f83\u5927\u7684\u4e8b\u52a1\uff0c\u53ef\u4ee5\u589e\u5927\u7f13\u5b58\u5927\u5c0f\u3002<br \/>\n\tinnodb_log_buffer_size=32M<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">15. innodb_log_file_size = 50M &nbsp;<br \/>\n\t\u6b64\u53c2\u6570\u786e\u5b9a\u6570\u636e\u65e5\u5fd7\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u4ee5M\u4e3a\u5355\u4f4d\uff0c\u66f4\u5927\u7684\u8bbe\u7f6e\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd.<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">16. innodb_log_files_in_group = 3 &nbsp;<br \/>\n\t\u4e3a\u63d0\u9ad8\u6027\u80fd\uff0cMySQL\u53ef\u4ee5\u4ee5\u5faa\u73af\u65b9\u5f0f\u5c06\u65e5\u5fd7\u6587\u4ef6\u5199\u5230\u591a\u4e2a\u6587\u4ef6\u3002\u63a8\u8350\u8bbe\u7f6e\u4e3a3<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">17.read_buffer_size = 1M &nbsp;<br \/>\n\tMySql \u8bfb\u5165\u7f13\u51b2\u533a\u5927\u5c0f\u3002\u5bf9\u8868\u8fdb\u884c\u987a\u5e8f\u626b\u63cf\u7684\u8bf7\u6c42\u5c06\u5206\u914d\u4e00\u4e2a\u8bfb\u5165\u7f13\u51b2\u533a\uff0cMySql\u4f1a\u4e3a\u5b83\u5206\u914d\u4e00\u6bb5\u5185\u5b58\u7f13\u51b2\u533a\u3002\u5982\u679c\u5bf9\u8868\u7684\u987a\u5e8f\u626b\u63cf\u8bf7\u6c42\u975e\u5e38\u9891\u7e41\uff0c\u5e76\u4e14\u4f60\u8ba4\u4e3a\u9891\u7e41\u626b\u63cf\u8fdb\u884c\u5f97\u592a\u6162\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0\u8be5\u53d8\u91cf\u503c\u4ee5\u53ca\u5185\u5b58\u7f13\u51b2\u533a\u5927\u5c0f\u63d0\u9ad8\u5176\u6027\u80fd\u3002\u548c sort_buffer_size\u4e00\u6837\uff0c\u8be5\u53c2\u6570\u5bf9\u5e94\u7684\u5206\u914d\u5185\u5b58\u4e5f\u662f\u6bcf\u4e2a\u8fde\u63a5\u72ec\u4eab<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">18.read_rnd_buffer_size = 16M&nbsp; &nbsp;<br \/>\n\tMySql \u7684\u968f\u673a\u8bfb\uff08\u67e5\u8be2\u64cd\u4f5c\uff09\u7f13\u51b2\u533a\u5927\u5c0f\u3002\u5f53\u6309\u4efb\u610f\u987a\u5e8f\u8bfb\u53d6\u884c\u65f6(\u4f8b\u5982\uff0c\u6309\u7167\u6392\u5e8f\u987a\u5e8f)\uff0c\u5c06\u5206\u914d\u4e00\u4e2a\u968f\u673a\u8bfb\u7f13\u5b58\u533a\u3002\u8fdb\u884c\u6392\u5e8f\u67e5\u8be2\u65f6\uff0cMySql\u4f1a\u9996\u5148\u626b\u63cf\u4e00\u904d\u8be5\u7f13\u51b2\uff0c\u4ee5\u907f\u514d\u78c1\u76d8\u641c\u7d22\uff0c\u63d0\u9ad8\u67e5\u8be2\u901f\u5ea6\uff0c\u5982\u679c\u9700\u8981\u6392\u5e8f\u5927\u91cf\u6570\u636e\uff0c\u53ef\u9002\u5f53\u8c03\u9ad8\u8be5\u503c\u3002\u4f46MySql\u4f1a\u4e3a\u6bcf\u4e2a\u5ba2\u6237\u8fde\u63a5\u53d1\u653e\u8be5\u7f13\u51b2\u7a7a\u95f4\uff0c\u6240\u4ee5\u5e94\u5c3d\u91cf\u9002\u5f53\u8bbe\u7f6e\u8be5\u503c\uff0c\u4ee5\u907f\u514d\u5185\u5b58\u5f00\u9500\u8fc7\u5927\u3002<br \/>\n\t\u6ce8\uff1a\u987a\u5e8f\u8bfb\u662f\u6307\u6839\u636e\u7d22\u5f15\u7684\u53f6\u8282\u70b9\u6570\u636e\u5c31\u80fd\u987a\u5e8f\u5730\u8bfb\u53d6\u6240\u9700\u8981\u7684\u884c\u6570\u636e\u3002\u968f\u673a\u8bfb\u662f\u6307\u4e00\u822c\u9700\u8981\u6839\u636e\u8f85\u52a9\u7d22\u5f15\u53f6\u8282\u70b9\u4e2d\u7684\u4e3b\u952e\u5bfb\u627e\u5b9e\u9645\u884c\u6570\u636e\uff0c\u800c\u8f85\u52a9\u7d22\u5f15\u548c\u4e3b\u952e\u6240\u5728\u7684\u6570\u636e\u6bb5\u4e0d\u540c\uff0c\u56e0\u6b64\u8bbf\u95ee\u65b9\u5f0f\u662f\u968f\u673a\u7684\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">19.bulk_insert_buffer_size = 64M&nbsp; &nbsp;<br \/>\n\t\u6279\u91cf\u63d2\u5165\u6570\u636e\u7f13\u5b58\u5927\u5c0f\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u63d2\u5165\u6548\u7387\uff0c\u9ed8\u8ba4\u4e3a8M<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">20.binary log<br \/>\n\tlog-bin=\/usr\/local\/mysql\/data\/mysql-bin<br \/>\n\tbinlog_cache_size = 2M&nbsp; \/\/\u4e3a\u6bcf\u4e2asession \u5206\u914d\u7684\u5185\u5b58\uff0c\u5728\u4e8b\u52a1\u8fc7\u7a0b\u4e2d\u7528\u6765\u5b58\u50a8\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7684\u7f13\u5b58, \u63d0\u9ad8\u8bb0\u5f55bin-log\u7684\u6548\u7387\u3002\u6ca1\u6709\u4ec0\u4e48\u5927\u4e8b\u52a1\uff0cdml\u4e5f\u4e0d\u662f\u5f88\u9891\u7e41\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u8bbe\u7f6e\u5c0f\u4e00\u70b9\uff0c\u5982\u679c\u4e8b\u52a1\u5927\u800c\u4e14\u591a\uff0cdml\u64cd\u4f5c\u4e5f\u9891\u7e41\uff0c\u5219\u53ef\u4ee5\u9002\u5f53\u7684\u8c03\u5927\u4e00\u70b9\u3002\u524d\u8005\u5efa\u8bae\u662f--1M\uff0c\u540e\u8005\u5efa\u8bae\u662f\uff1a\u5373 2--4M<br \/>\n\tmax_binlog_cache_size = 8M \/\/\u8868\u793a\u7684\u662fbinlog \u80fd\u591f\u4f7f\u7528\u7684\u6700\u5927cache \u5185\u5b58\u5927\u5c0f<br \/>\n\tmax_binlog_size= 512M&nbsp; \/\/\u6307\u5b9abinlog\u65e5\u5fd7\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u5982\u679c\u5f53\u524d\u7684\u65e5\u5fd7\u5927\u5c0f\u8fbe\u5230max_binlog_size\uff0c\u8fd8\u4f1a\u81ea\u52a8\u521b\u5efa\u65b0\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u3002\u4f60\u4e0d\u80fd\u5c06\u8be5\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u5927\u4e8e1GB\u6216\u5c0f\u4e8e4096\u5b57\u8282\u3002\u9ed8\u8ba4\u503c\u662f1GB\u3002\u5728\u5bfc\u5165\u5927\u5bb9\u91cf\u7684sql\u6587\u4ef6\u65f6\uff0c\u5efa\u8bae\u5173\u95edsql_log_bin\uff0c\u5426\u5219\u786c\u76d8\u625b\u4e0d\u4f4f\uff0c\u800c\u4e14\u5efa\u8bae\u5b9a\u671f\u505a\u5220\u9664\u3002<br \/>\n\texpire_logs_days = 7&nbsp; \/\/\u5b9a\u4e49\u4e86mysql\u6e05\u9664\u8fc7\u671f\u65e5\u5fd7\u7684\u65f6\u95f4\u3002<br \/>\n\t\u4e8c\u8fdb\u5236\u65e5\u5fd7\u81ea\u52a8\u5220\u9664\u7684\u5929\u6570\u3002\u9ed8\u8ba4\u503c\u4e3a0,\u8868\u793a&ldquo;\u6ca1\u6709\u81ea\u52a8\u5220\u9664&rdquo;\u3002<br \/>\n\tmysqladmin flush-logs \u4e5f\u53ef\u4ee5\u91cd\u65b0\u5f00\u59cb\u65b0\u7684binarylog<\/span><\/span>\n<\/p>\n<p>\n\t<strong><span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u4e8c\u3001\u65b0\u65e7\u914d\u7f6e\u5bf9\u6bd4\u6d4b\u8bd5<\/span><\/span><\/strong>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">1\u3001\u88ab\u6d4b\u673a\u5668\u8f6f\u786c\u4ef6\u914d\u7f6e<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">12\u683824\u7ebf\u7a0b\u5904\u7406\u5668\uff0c\u5185\u5b5864GB<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2018\/03\/dell_hardware_config.png\" \/><br \/>\n\t2\u3001\u7f16\u5199shell\u811a\u672c\u63d2\u5165\u6d4b\u8bd5\u6570\u636e40000\u6761<br \/>\n\t\u811a\u672c\u5982\u4e0b\uff0c<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">#!\/bin\/bash&nbsp;&nbsp; &nbsp;<br \/>\n\tHOSTNAME=&quot;172.18.23.198&quot;<br \/>\n\tPORT=&quot;8034&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tUSERNAME=&quot;root&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tPASSWORD=&quot;123456&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n\tDBNAME=&quot;test1&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tTABLENAME=&quot;tb1&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\t#ceate database&nbsp;&nbsp; &nbsp;<br \/>\n\tmysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e &quot;drop database if exists ${DBNAME}&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tcreate_db_sql=&quot;create database if not exists ${DBNAME}&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tmysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e&quot;${create_db_sql}&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\t#create table&nbsp;&nbsp; &nbsp;<br \/>\n\tcreate_table_sql=&quot;create table if not exists ${TABLENAME}(stuid int not null primary key,stuname varchar(20) not null,stusex char(1)&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n\tnot null,cardid varchar(20) not null,birthday datetime,entertime datetime,address varchar(100)default null)&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tmysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e&quot;${create_table_sql}&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\t#insert data to table&nbsp;&nbsp; &nbsp;<br \/>\n\ti=&quot;1&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\twhile [ $i -le 40000 ]&nbsp;&nbsp; &nbsp;<br \/>\n\tdo&nbsp;&nbsp; &nbsp;<br \/>\n\tinsert_sql=&quot;insert into ${TABLENAME}&nbsp; values($i,&#39;zhangsan&#39;,&#39;1&#39;,&#39;21276387261874682&#39;,&#39;1999-10-10&#39;,&#39;2017-10-24&#39;,&#39;beijingchangpingqu&#39;)&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tmysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e&quot;${insert_sql}&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tlet i++&nbsp;&nbsp; &nbsp;<br \/>\n\tdone&nbsp;&nbsp; &nbsp;<br \/>\n\t#select data&nbsp;&nbsp; &nbsp;<br \/>\n\tselect_sql=&quot;select count(*) from ${TABLENAME}&quot;&nbsp;&nbsp; &nbsp;<br \/>\n\tmysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e&quot;${select_sql}&quot;<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u63d2\u5165\u5b8c\u6210\u540e\u7684\u622a\u56fe\u5982\u4e0b\uff0c<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2018\/03\/insert_40000_records.png\" \/><br \/>\n\t3\u3001\u5bf9\u672a\u4f18\u5316\u7684MySQL\u670d\u52a1\u5668\u6267\u884c\u538b\u529b\u6d4b\u8bd5<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u672a\u4f18\u5316\u7684MySQL\u4e3b\u914d\u7f6emy.cnf\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff0c<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\"># The following options will be passed to all MySQL clients<br \/>\n\t[client]<br \/>\n\t#password&nbsp;&nbsp;&nbsp; = your_password<br \/>\n\tport&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 8067<br \/>\n\tsocket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = \/data\/mysql\/mysql.sock<br \/>\n\t&nbsp;<br \/>\n\t# Here follows entries for some specific programs<br \/>\n\t&nbsp;<br \/>\n\t# The MySQL server<br \/>\n\t[mysqld]<br \/>\n\tdatadir=\/data\/mysql<br \/>\n\tbasedir=\/usr\/local\/mysql<br \/>\n\tport&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 8067<br \/>\n\tsocket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = \/data\/mysql\/mysql.sock<br \/>\n\tskip-external-locking<br \/>\n\tkey_buffer_size = 16M<br \/>\n\tmax_allowed_packet = 256M<br \/>\n\ttable_open_cache = 64<br \/>\n\tsort_buffer_size = 512K<br \/>\n\tnet_buffer_length = 8K<br \/>\n\tread_buffer_size = 256K<br \/>\n\tread_rnd_buffer_size = 512K<br \/>\n\tmyisam_sort_buffer_size = 8M<br \/>\n\t&nbsp;<br \/>\n\tdefault_storage_engine=InnoDB<br \/>\n\t&nbsp;<br \/>\n\t# Don&#39;t listen on a TCP\/IP port at all. This can be a security enhancement,<br \/>\n\t# if all processes that need to connect to mysqld run on the same host.<br \/>\n\t# All interaction with mysqld must be made via Unix sockets or named pipes.<br \/>\n\t# Note that using this option without enabling named pipes on Windows<br \/>\n\t# (via the &quot;enable-named-pipe&quot; option) will render mysqld useless!<br \/>\n\t#<br \/>\n\t#skip-networking<br \/>\n\t&nbsp;<br \/>\n\t# Replication Master Server (default)<br \/>\n\t# binary logging is required for replication<br \/>\n\tlog-bin=mysql-bin<br \/>\n\t&nbsp;<br \/>\n\t# binary logging format - mixed recommended<br \/>\n\tbinlog_format=mixed<br \/>\n\t&nbsp;<br \/>\n\t# required unique id between 1 and 2^32 - 1<br \/>\n\t# defaults to 1 if master-host is not set<br \/>\n\t# but will not function as a master if omitted<br \/>\n\tserver-id&nbsp;&nbsp;&nbsp; = 1<br \/>\n\t&nbsp;<br \/>\n\t# Replication Slave (comment out master section to use this)<br \/>\n\t#<br \/>\n\t# To configure this host as a replication slave, you can choose between<br \/>\n\t# two methods :<br \/>\n\t#<br \/>\n\t# 1) Use the CHANGE MASTER TO command (fully described in our manual) -<br \/>\n\t#&nbsp;&nbsp;&nbsp; the syntax is:<br \/>\n\t#<br \/>\n\t#&nbsp;&nbsp;&nbsp; CHANGE MASTER TO MASTER_HOST=&lt;host&gt;, MASTER_PORT=&lt;port&gt;,<br \/>\n\t#&nbsp;&nbsp;&nbsp; MASTER_USER=&lt;user&gt;, MASTER_PASSWORD=&lt;password&gt; ;<br \/>\n\t#<br \/>\n\t#&nbsp;&nbsp;&nbsp; where you replace &lt;host&gt;, &lt;user&gt;, &lt;password&gt; by quoted strings and<br \/>\n\t#&nbsp;&nbsp;&nbsp; &lt;port&gt; by the master&#39;s port number (3306 by default).<br \/>\n\t#<br \/>\n\t#&nbsp;&nbsp;&nbsp; Example:<br \/>\n\t#<br \/>\n\t#&nbsp;&nbsp;&nbsp; CHANGE MASTER TO MASTER_HOST=&#39;125.564.12.1&#39;, MASTER_PORT=3306,<br \/>\n\t#&nbsp;&nbsp;&nbsp; MASTER_USER=&#39;joe&#39;, MASTER_PASSWORD=&#39;secret&#39;;<br \/>\n\t#<br \/>\n\t# OR<br \/>\n\t#<br \/>\n\t# 2) Set the variables below. However, in case you choose this method, then<br \/>\n\t#&nbsp;&nbsp;&nbsp; start replication for the first time (even unsuccessfully, for example<br \/>\n\t#&nbsp;&nbsp;&nbsp; if you mistyped the password in master-password and the slave fails to<br \/>\n\t#&nbsp;&nbsp;&nbsp; connect), the slave will create a master.info file, and any later<br \/>\n\t#&nbsp;&nbsp;&nbsp; change in this file to the variables&#39; values below will be ignored and<br \/>\n\t#&nbsp;&nbsp;&nbsp; overridden by the content of the master.info file, unless you shutdown<br \/>\n\t#&nbsp;&nbsp;&nbsp; the slave server, delete master.info and restart the slaver server.<br \/>\n\t#&nbsp;&nbsp;&nbsp; For that reason, you may want to leave the lines below untouched<br \/>\n\t#&nbsp;&nbsp;&nbsp; (commented) and instead use CHANGE MASTER TO (see above)<br \/>\n\t#<br \/>\n\t# required unique id between 2 and 2^32 - 1<br \/>\n\t# (and different from the master)<br \/>\n\t# defaults to 2 if master-host is set<br \/>\n\t# but will not function as a slave if omitted<br \/>\n\t#server-id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 2<br \/>\n\t#<br \/>\n\t# The replication master for this slave - required<br \/>\n\t#master-host&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp; &lt;hostname&gt;<br \/>\n\t#<br \/>\n\t# The username the slave will use for authentication when connecting<br \/>\n\t# to the master - required<br \/>\n\t#master-user&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp; &lt;username&gt;<br \/>\n\t#<br \/>\n\t# The password the slave will authenticate with when connecting to<br \/>\n\t# the master - required<br \/>\n\t#master-password =&nbsp;&nbsp; &lt;password&gt;<br \/>\n\t#<br \/>\n\t# The port the master is listening on.<br \/>\n\t# optional - defaults to 3306<br \/>\n\t#master-port&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; &lt;port&gt;<br \/>\n\t#<br \/>\n\t# binary logging - not required for slaves, but recommended<br \/>\n\tlog-bin=mysql-bin<br \/>\n\t&nbsp;<br \/>\n\t# Uncomment the following if you are using InnoDB tables<br \/>\n\t#innodb_data_home_dir = \/usr\/local\/mysql\/data<br \/>\n\t#innodb_data_file_path = ibdata1:10M:autoextend<br \/>\n\t#innodb_log_group_home_dir = \/usr\/local\/mysql\/data<br \/>\n\t# You can set .._buffer_pool_size up to 50 - 80 %<br \/>\n\t# of RAM but beware of setting memory usage too high<br \/>\n\tinnodb_buffer_pool_size = 16384M<br \/>\n\t#innodb_additional_mem_pool_size = 2M<br \/>\n\t# Set .._log_file_size to 25 % of buffer pool size<br \/>\n\tinnodb_log_file_size = 250M<br \/>\n\tinnodb_log_buffer_size = 8M<br \/>\n\tinnodb_flush_log_at_trx_commit = 2<br \/>\n\tinnodb_lock_wait_timeout = 120<br \/>\n\tinnodb_file_per_table = ON<br \/>\n\t&nbsp;<br \/>\n\tsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">[mysqldump]<br \/>\n\tquick<br \/>\n\tmax_allowed_packet = 16M<br \/>\n\t&nbsp;<br \/>\n\t[mysql]<br \/>\n\tno-auto-rehash<br \/>\n\t# Remove the next comment character if you are not familiar with SQL<br \/>\n\t#safe-updates<br \/>\n\t&nbsp;<br \/>\n\t[myisamchk]<br \/>\n\tkey_buffer_size = 20M<br \/>\n\tsort_buffer_size = 20M<br \/>\n\tread_buffer = 2M<br \/>\n\twrite_buffer = 2M<br \/>\n\t&nbsp;<br \/>\n\t[mysqlhotcopy]<br \/>\n\tinteractive-timeout<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u538b\u529b\u6d4b\u8bd5\u7684shell\u811a\u672c\u5982\u4e0b\uff0c\u5171\u6d4b\u8bd510\u6b21\uff0c\u5e73\u5747\u8017\u65f6 <strong><span style=\"color:#FF0000\">10.6856<\/span><\/strong> s\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">#!\/bin\/bash<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">i=&quot;1&quot;<br \/>\n\ttest_log_file=&quot;\/tmp\/sql_load_test.txt&quot;<br \/>\n\t&gt;${test_log_file} 2&gt;\/dev\/null<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">echo -e &quot;\\nLoad Test Begin...\\n&quot;<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">while [ ${i} -le 10 ]<br \/>\n\tdo<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">mysqlslap --defaults-file=\/etc\/my.cnf --concurrency=100 --iterations=1 --create-schema=&#39;test1&#39; --query=&#39;select * from test1.tb1&#39; engine=innodb --number-of-queries=2000 -uroot -p123456 -P 8034 -h 172.18.23.198 --verbose 2&gt;\/dev\/null &gt;&gt;${test_log_file}<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">ping -c 2 127.0.0.1 1&gt;\/dev\/null 2&gt;&amp;1<br \/>\n\tlet i++<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">done<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">awk &#39;\/Average.+all queries\/{sum+=$09}END{printf &quot;Average Query Time : %s seconds.\\n\\n&quot;,sum\/10}&#39; ${test_log_file}<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u6267\u884c\u7ed3\u679c\u5982\u4e0b\u56fe\uff0c<\/span><\/span>\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2018\/03\/mysql_untuned.png\" \/><br \/>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">4\u3001\u5bf9\u4f18\u5316\u540e\u7684MySQL\u670d\u52a1\u5668\u6267\u884c\u538b\u529b\u6d4b\u8bd5<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u4f18\u5316\u540e\u7684MySQL\u4e3b\u914d\u7f6e\u6587\u4ef6my.cnf\u5185\u5bb9\u5982\u4e0b\uff0c<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\"># The following options will be passed to all MySQL clients<br \/>\n\t[client]<br \/>\n\t#password&nbsp;&nbsp; &nbsp;= your_password<br \/>\n\tport&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;= 8067<br \/>\n\tsocket&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;= \/data\/mysql\/mysql.sock<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\"># Here follows entries for some specific programs<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\"># The MySQL server<br \/>\n\t[mysqld]<br \/>\n\tdatadir=\/data\/mysql<br \/>\n\tbasedir=\/usr\/local\/mysql<br \/>\n\tport&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;= 8067<br \/>\n\tsocket&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;= \/data\/mysql\/mysql.sock<br \/>\n\t#log-error=\/usr\/local\/mysql\/log\/error.log &nbsp;<br \/>\n\t#log=\/usr\/local\/mysql\/log\/mysql.log<br \/>\n\tskip-external-locking<br \/>\n\ttable_open_cache = 64<br \/>\n\tnet_buffer_length = 8K<br \/>\n\tmyisam_sort_buffer_size = 8M<br \/>\n\tdefault_storage_engine=InnoDB<br \/>\n\t#log_slow_queries=\/data\/mysql\/DELL_S7-slow.log<br \/>\n\tinnodb_file_per_table = ON<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">slow_query_log=1&nbsp;&nbsp; &nbsp;<br \/>\n\tlong_query_time=1&nbsp;&nbsp; &nbsp;<br \/>\n\tlog-queries-not-using-indexes&nbsp;&nbsp; &nbsp;<br \/>\n\tmax_connections=1024<br \/>\n\tback_log=1024&nbsp;&nbsp; &nbsp;<br \/>\n\twait_timeout=100&nbsp;&nbsp; &nbsp;<br \/>\n\tinteractive_timeout=1800&nbsp; &nbsp;<br \/>\n\tkey_buffer_size=128M<br \/>\n\tquery_cache_size=256M<br \/>\n\tquery_cache_type=1<br \/>\n\tquery_cache_limit=50M&nbsp;&nbsp; &nbsp;<br \/>\n\tmax_connect_errors=20&nbsp;&nbsp; &nbsp;<br \/>\n\tsort_buffer_size=2M&nbsp;&nbsp; &nbsp;<br \/>\n\tmax_allowed_packet=32M&nbsp;&nbsp; &nbsp;<br \/>\n\tjoin_buffer_size=2M&nbsp;&nbsp; &nbsp;<br \/>\n\tthread_cache_size=300&nbsp;&nbsp; &nbsp;<br \/>\n\tinnodb_buffer_pool_size=32G&nbsp;&nbsp; &nbsp;<br \/>\n\tinnodb_flush_log_at_trx_commit=1<br \/>\n\tinnodb_log_buffer_size=32M&nbsp;&nbsp; &nbsp;<br \/>\n\tinnodb_log_file_size=64M&nbsp;&nbsp; &nbsp;<br \/>\n\tinnodb_log_files_in_group=3<br \/>\n\tbulk_insert_buffer_size=64M<br \/>\n\tlog-bin=mysql-bin&nbsp;&nbsp; &nbsp;<br \/>\n\tbinlog_cache_size=2M&nbsp;&nbsp; &nbsp;<br \/>\n\tmax_binlog_cache_size=8M&nbsp;&nbsp; &nbsp;<br \/>\n\tmax_binlog_size=512M&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n\tread_buffer_size=1M&nbsp;&nbsp; &nbsp;<br \/>\n\tread_rnd_buffer_size=16M&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n\tserver-id=1&nbsp; &nbsp;<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">[mysqldump]<br \/>\n\tquick<br \/>\n\tmax_allowed_packet = 16M<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">[mysql]<br \/>\n\tno-auto-rehash<br \/>\n\tdefault-character-set=utf8<br \/>\n\t# Remove the next comment character if you are not familiar with SQL<br \/>\n\t#safe-updates<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">[myisamchk]<br \/>\n\tkey_buffer_size = 20M<br \/>\n\tsort_buffer_size = 20M<br \/>\n\tread_buffer = 2M<br \/>\n\twrite_buffer = 2M<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000CD\"><em><span style=\"font-size: 16px\"><span style=\"font-family: verdana, geneva, sans-serif\">[mysqlhotcopy]<br \/>\n\tinteractive-timeout<\/span><\/span><\/em><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u522b\u5fd8\u4e86\u628alog\u6587\u4ef6\u79fb\u52a8\u5230\u5176\u4ed6\u5730\u65b9\uff0c\u5426\u5219MySQL\u542f\u52a8\u4f1a\u62a5\u9519\uff0c\u8fd9\u662f5.6.x\u7248\u672c\u7684\u8bdf\u75c5\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\">[root@S7 pc]#&nbsp; <span style=\"font-family: verdana, geneva, sans-serif\">mv \/usr\/local\/data\/ib_log* \/tmp<br \/>\n\t\u6267\u884c\u538b\u529b\u6d4b\u8bd5\u7684\u811a\u672c\u540c\u4e0a\uff0c\u5171\u6d4b\u8bd510\u6b21\uff0c\u5e73\u5747\u8017\u65f6<span style=\"color:#FF0000\"><strong> 4.4854 <\/strong><\/span>s\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family: verdana, geneva, sans-serif\">\u6267\u884c\u7ed3\u679c\u5982\u4e0b\u56fe\uff0c<\/span><\/span>\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2018\/03\/mysql_tuned.png\" \/>\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">\u4ece\u6d4b\u8bd5\u7ed3\u679c\u770b\uff0c\u4f18\u5316\u540e\u7684\u67e5\u8be2\u6027\u80fd\u662f\u672a\u4f18\u5316\u76842\u500d\u591a\uff0c\u6027\u80fd\u5927\u5927\u63d0\u5347\u3002<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001MySQL\u4f18\u5316\u53c2\u6570\u8be6\u89e3 1)&nbsp;&nbsp; \u8fde\u63a5\u8bf7\u6c42\u7684\u53d8\u91cf Max_connections Mysql\u7684\u6700\u5927\u8fde\u63a5\u6570\uff0c\u5982\u679c\u670d\u52a1\u5668\u7684\u5e76\u53d1\u8bf7\u6c42\u91cf\u6bd4\u8f83\u5927\uff0c\u53ef\u4ee5\u8c03\u9ad8\u8fd9\u4e2a\u503c\uff0c\u5f53\u7136\u8fd9\u662f\u8981\u5efa\u7acb\u5728\u673a\u5668\u80fd\u591f\u652f\u6491\u7684\u60c5\u51b5\u4e0b\uff0c\u56e0\u4e3a\u5982\u679c\u8fde\u63a5\u6570\u8d8a\u6765\u8d8a\u591a\uff0cmysql\u4f1a\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u63d0\u4f9b\u7f13\u51b2\u533a\uff0c\u5c31\u4f1a\u5f00\u9500\u7684\u8d8a\u591a\u7684\u5185\u5b58\uff0c\u6240\u4ee5\u9700\u8981\u9002\u5f53\u7684\u8c03\u6574\u8be5\u503c\uff0c\u4e0d\u80fd\u968f\u4fbf\u53bb\u63d0\u9ad8\u8bbe\u503c\u3002 \u4fee\u6539\/etc\/my.cnf\u5728[mysqld]\u4e0b\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0c\u8bbe\u7f6e\u6700\u5927\u8fde\u63a5\u6570\u4e3a1024\uff0c\u91cd\u542fmysql\u670d\u52a1\u9a8c\u8bc1 vim\/etc\/my.cnf \u6dfb\u52a0max_connections=1024 2\uff09back_log mysql\u80fd\u6682\u5b58\u7684\u8fde\u63a5\u6570\u91cf\uff0c\u5f53\u4e3b\u8981mysql\u7ebf\u7a0b\u5728\u4e00\u4e2a\u5f88\u77ed\u65f6\u95f4\u5185\u5f97\u5230\u975e\u5e38\u591a\u7684\u8fde\u63a5\u8bf7\u6c42\u65f6\u5019\u5b83\u5c31\u4f1a\u8d77\u4f5c\u7528\uff0c\u5982\u679cmysql\u7684\u8fde\u63a5\u6570\u636e\u8fbe\u5230max_connections\u65f6\u5019\uff0c\u65b0\u6765\u7684\u8bf7\u6c42\u5c06\u4f1a\u88ab\u5b58\u5728\u5806\u6808\u4e2d\uff0c\u7b49\u5f85\u67d0\u4e00\u8fde\u63a5\u91ca\u653e\u8d44\u6e90\uff0c\u8be5\u63a8\u6808\u7684\u6570\u91cf\u53caback_log,\u5982\u679c\u7b49\u5f85\u8fde\u63a5\u7684\u6570\u91cf\u8d85\u8fc7back_log\uff0c\u5c06\u4e0d\u88ab\u6388\u4e88\u8fde\u63a5\u8d44\u6e90 back_log\u503c\u6307\u51fa\u5728mysql\u6682\u65f6\u505c\u6b62\u56de\u7b54\u65b0\u8bf7\u6c42\u4e4b\u524d\u7684\u77ed\u65f6\u95f4\u5185\u6709\u591a\u5c11\u4e2a\u8bf7\u6c42\u53ef\u4ee5\u88ab\u5b58\u5728\u63a8\u6808\u4e2d\uff0c\u53ea\u6709\u5982\u679c\u671f\u671b\u5728\u4e00\u4e2a\u77ed\u65f6\u95f4\u5185\u6709\u5f88\u591a\u8fde\u63a5\u7684\u65f6\u5019\u9700\u8981\u589e\u52a0\u5b83 \u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770bback_log\u7684\u8bbe\u7f6e\u9ed8\u8ba4\u662f254 \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7MySQL\u4e3b\u914d\u7f6e\u4fee\u6539\u5b83\u7684\u5927\u5c0f\uff0c\u8bbe\u7f6e\u6700\u5927\u8fde\u63a5\u6570\u4e3a\uff1a1024\u968f\u540e\u91cd\u542fMySQL\u670d\u52a1\u518d\u6b21\u67e5\u770b vim \/etc\/my.cnf \u6dfb\u52a0\uff1aback_log=1024 3\uff09wait_timeout\u548cinteractive_timeout wait_timeout\uff1a\u6307\u7684\u662fmysql\u5728\u5173\u95ed\u4e00\u4e2a\u975e\u4ea4\u4e92\u7684\u8fde\u63a5\u4e4b\u524d\u6240\u8981\u7b49\u5f85\u7684\u79d2\u6570 interactive_timeoutz\uff1a\u6307\u7684\u662fmysql\u5728\u5173\u95ed\u4e00\u4e2a\u4ea4\u4e92\u7684\u8fde\u63a5\u4e4b\u524d\u6240\u9700\u8981\u7b49\u5f85\u7684\u79d2\u6570\uff0c\u6bd4\u5982\u6211\u4eec\u5728\u7ec8\u7aef\u4e0a\u8fdb\u884cmysql\u7ba1\u7406\uff0c\u4f7f\u7528\u7684\u5373\u4f7f\u4ea4\u4e92\u7684\u8fde\u63a5\uff0c\u8fd9\u65f6\u5019\uff0c\u5982\u679c\u6ca1\u6709\u64cd\u4f5c\u7684\u65f6\u95f4\u8d85\u8fc7\u4e86interactive_time\u8bbe\u7f6e\u7684\u65f6\u95f4\u5c31\u4f1a\u81ea\u52a8\u7684\u65ad\u5f00\uff0c\u9ed8\u8ba4\u7684\u662f28800\uff0c\u53ef\u8c03\u4f18\u4e3a7200\u3002wait_timeout:\u5982\u679c\u8bbe\u7f6e\u592a\u5c0f\uff0c\u90a3\u4e48\u8fde\u63a5\u5173\u95ed\u7684\u5c31\u5f88\u5feb\uff0c\u4ece\u800c\u4f7f\u4e00\u4e9b\u6301\u4e45\u7684\u8fde\u63a5\u4e0d\u8d77\u4f5c\u7528 \u5982\u679c\u8bbe\u7f6e\u592a\u5927\uff0c\u5bb9\u6613\u9020\u6210\u8fde\u63a5\u6253\u5f00\u65f6\u95f4\u8fc7\u957f\uff0c\u5728show processlist\u65f6\u5019\uff0c\u80fd\u770b\u5230\u5f88\u591a\u7684\u8fde\u63a5 \u4e00\u822c\u5e0c\u671bwait_timeout\u5c3d\u53ef\u80fd\u4f4e \u67e5\u770bwait_timeout\u548cinteractive_timeout\u7684\u8bbe\u7f6e \u4fee\u6539\/etc\/my.cnf\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9 wait_timeout=100 interactive_timeout=100 4\uff09query_cache_size\uff08\u67e5\u8be2\u7f13\u5b58\u7b80\u79f0QC\uff09 \u4f7f\u7528\u67e5\u8be2\u7f13\u51b2\uff0cmysql\u5c06\u67e5\u8be2\u7ed3\u679c\u5b58\u653e\u5728\u7f13\u51b2\u533a\u4e2d\uff0c\u4eca\u540e\u5bf9\u4e8e\u540c\u6837\u7684select\u8bed\u53e5\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09,\u5c06\u76f4\u63a5\u4ece\u7f13\u51b2\u533a\u4e2d\u8bfb\u53d6\u7ed3\u679c\u3002 \u4e00\u4e2asql\u67e5\u8be2\u5982\u679c\u4ee5select\u5f00\u5934\uff0c\u90a3\u4e48mysql\u670d\u52a1\u5668\u5c06\u5c1d\u8bd5\u5bf9\u5176\u4f7f\u7528\u67e5\u8be2\u7f13\u5b58\u3002 \u6ce8\uff1a\u4e24\u4e2asql\u8bed\u53e5\uff0c\u53ea\u8981\u60f3\u5dee\u54ea\u6015\u662f\u4e00\u4e2a\u5b57\u7b26\uff08\u5217\u5982\u5927\u5c0f\u5199\u4e0d\u4e00\u6837\uff1b\u591a\u4e00\u4e2a\u7a7a\u683c\u7b49\uff09,\u90a3\u4e48\u8fd9\u4e24\u4e2asql\u5c06\u4f7f\u7528\u4e0d\u540c\u7684\u4e00\u4e2acache\u3002 \u4e0a\u8ff0\u72b6\u6001\u503c\u53ef\u4ee5\u4f7f\u7528show status like &#39;Qcache%\u83b7\u5f97&#39; Qcache_free_blocks\uff1a\u7f13\u5b58\u4e2d\u76f8\u90bb\u5185\u5b58\u5757\u7684\u4e2a\u6570\u3002\u5982\u679c\u8be5\u503c\u663e\u793a\u8f83\u5927\uff0c\u5219\u8bf4\u660eQuery Cache \u4e2d\u7684\u5185\u5b58\u788e\u7247\u8f83\u591a\u4e86\uff0cFLUSH QUERY CACHE\u4f1a\u5bf9\u7f13\u5b58\u4e2d\u7684\u788e\u7247\u8fdb\u884c\u6574\u7406\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u7a7a\u95f2\u5757\u3002 \u6ce8\uff1a\u5f53\u4e00\u4e2a\u8868\u88ab\u66f4\u65b0\u4e4b\u540e\uff0c\u548c\u5b83\u76f8\u5173\u7684cache blocks\u5c06\u88abfree\u3002\u4f46\u662f\u8fd9\u4e2ablock\u4f9d\u7136\u53ef\u80fd\u5b58\u5728\u961f\u5217\u4e2d\uff0c\u9664\u975e\u662f\u5728\u961f\u5217\u7684\u5c3e\u90e8\u3002\u53ef\u4ee5\u7528FLUSH QUERY CACHE\u8bed\u53e5\u6765\u6e05\u7a7afree blocks Qcache_free_memory\uff1aQuery Cache\u4e2d\u76ee\u524d\u5269\u4f59\u7684\u5185\u5b58\u5927\u5c0f\u3002\u901a\u8fc7\u8fd9\u4e2a\u53c2\u6570\u6211\u4eec\u53ef\u4ee5\u8f83\u4e3a\u51c6\u786e\u7684\u89c2\u5bdf\u51fa\u5f53\u524d\u7cfb\u7edf\u4e2d\u7684Query Cache\u5185\u5b58\u5927\u5c0f\u662f\u5426\u8db3\u591f\uff0c\u662f\u9700\u8981\u589e\u52a0\u8fd8\u662f\u8fc7\u591a\u4e86\u3002 Qcache_hits\uff1a\u8868\u793a\u6709\u591a\u5c11\u6b21\u547d\u4e2d\u7f13\u5b58\u3002\u6211\u4eec\u4e3b\u8981\u53ef\u4ee5\u901a\u8fc7\u8be5\u503c\u6765\u9a8c\u8bc1\u6211\u4eec\u7684\u67e5\u8be2\u7f13\u5b58\u7684\u6548\u679c\u3002\u6570\u5b57\u8d8a\u5927\uff0c\u7f13\u5b58\u6548\u679c\u8d8a\u7406\u60f3\u3002 Qcache_inserts\uff1a\u8868\u793a\u591a\u5c11\u6b21\u672a\u547d\u4e2d\u7136\u540e\u63d2\u5165\uff0c\u610f\u601d\u662f\u65b0\u6765\u7684SQL\u8bf7\u6c42\u5728\u7f13\u5b58\u4e2d\u672a\u627e\u5230\uff0c\u4e0d\u5f97\u4e0d\u6267\u884c\u67e5\u8be2\u5904\u7406\uff0c\u6267\u884c\u67e5\u8be2\u5904\u7406\u540e\u628a\u7ed3\u679cinsert\u5230\u67e5\u8be2\u7f13\u5b58\u4e2d\u3002\u8fd9\u6837\u7684\u60c5\u51b5\u7684\u6b21\u6570\u8d8a\u591a\uff0c\u8868\u793a\u67e5\u8be2\u7f13\u5b58\u5e94\u7528\u5230\u7684\u6bd4\u8f83\u5c11\uff0c\u6548\u679c\u4e5f\u5c31\u4e0d\u7406\u60f3\u3002\u5f53\u7136\u7cfb\u7edf\u521a\u542f\u52a8\u540e\uff0c\u67e5\u8be2\u7f13\u5b58\u662f\u7a7a\u7684\uff0c\u8fd9\u5f88\u6b63\u5e38\u3002 Qcache_lowmem_prunes\uff1a\u591a\u5c11\u6761Query\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3\u800c\u88ab\u6e05\u9664\u51faQuery Cache\u3002\u901a\u8fc7&ldquo;Qcache_lowmem_prunes&rdquo;\u548c&ldquo;Qcache_free_memory&rdquo;\u76f8\u4e92\u7ed3\u5408\uff0c\u80fd\u591f\u66f4\u6e05\u695a\u7684\u4e86\u89e3\u5230\u6211\u4eec\u7cfb\u7edf\u4e2dQuery Cache \u7684\u5185\u5b58\u5927\u5c0f\u662f\u5426\u771f\u7684\u8db3\u591f\uff0c\u662f\u5426\u975e\u5e38\u9891\u7e41\u7684\u51fa\u73b0\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3\u800c\u6709Query\u88ab\u6362\u51fa\u3002\u8fd9\u4e2a\u6570\u5b57\u6700\u597d\u957f\u65f6\u95f4\u6765\u770b\uff1b\u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u5728\u4e0d\u65ad\u589e\u957f\uff0c\u5c31\u8868\u793a\u53ef\u80fd\u788e\u7247\u975e\u5e38\u4e25\u91cd\uff0c\u6216\u8005\u5185\u5b58\u5f88\u5c11\u3002\uff08\u4e0a\u9762\u7684free_blocks\u548cfree_memory\u53ef\u4ee5\u544a\u8bc9\u60a8\u5c5e\u4e8e\u54ea\u79cd\u60c5\u51b5\uff09 Qcache_not_cached\uff1a\u4e0d\u9002\u5408\u8fdb\u884c\u7f13\u5b58\u7684\u67e5\u8be2\u7684\u6570\u91cf\uff0c\u901a\u5e38\u662f\u7531\u4e8e\u8fd9\u4e9b\u67e5\u8be2\u4e0d\u662f SELECT\u8bed\u53e5\u6216\u8005\u7528\u4e86now()\u4e4b\u7c7b\u7684\u51fd\u6570\u3002&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/1229"}],"collection":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1229"}],"version-history":[{"count":6,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/1229\/revisions"}],"predecessor-version":[{"id":1254,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/1229\/revisions\/1254"}],"wp:attachment":[{"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}