{"id":5481,"date":"2024-11-14T08:08:32","date_gmt":"2024-11-14T00:08:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5481\/"},"modified":"2024-11-14T08:08:32","modified_gmt":"2024-11-14T00:08:32","slug":"mysql%e8%bf%9e%e6%8e%a5%e6%95%b0%e5%8d%a0%e6%bb%a1%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5481\/","title":{"rendered":"mysql\u8fde\u63a5\u6570\u5360\u6ee1\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  mysql \u8fde\u63a5\u8fc7\u591a\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002\u89e3\u51b3\u6b65\u9aa4\u5305\u62ec\uff1a\u627e\u51fa\u6700\u5927\u8fde\u63a5\u9650\u5236\u3002\u589e\u52a0\u8fde\u63a5\u9650\u5236\u3002\u6740\u6b7b\u8d85\u51fa\u9650\u5236\u7684\u8fde\u63a5\u3002\u9650\u5236\u6bcf\u4e2a\u7528\u6237\u8fde\u63a5\u6570\u3002\u4f18\u5316\u6570\u636e\u5e93\u67e5\u8be2\u4ee5\u51cf\u5c11\u8fde\u63a5\u3002\u4f7f\u7528\u8fde\u63a5\u6c60\u590d\u7528\u8fde\u63a5\u3002\u5b9a\u671f\u76d1\u89c6\u8fde\u63a5\u4f7f\u7528\u60c5\u51b5\u4ee5\u68c0\u6d4b\u95ee\u9898\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052903332571848.jpg\" class=\"aligncenter\" title=\"mysql\u8fde\u63a5\u6570\u5360\u6ee1\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"mysql\u8fde\u63a5\u6570\u5360\u6ee1\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u8fde\u63a5\u8fc7\u591a\u95ee\u9898<\/strong><\/p>\n<p>\u5f53 MySQL \u8fde\u63a5\u6570\u8fc7\u591a\u65f6\uff0c\u4f1a\u4e25\u91cd\u5f71\u54cd\u6570\u636e\u5e93\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. IDENTIFY THE MAXIMUM CONNECTION LIMIT<\/strong><\/p>\n<p>\u627e\u51fa MySQL \u670d\u52a1\u5668\u7684\u5f53\u524d\u6700\u5927\u8fde\u63a5\u9650\u5236\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a<\/p>\n<pre>show variables like 'max_connections';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. INCREASE THE CONNECTION LIMIT<\/strong><\/p>\n<p>\u5982\u679c\u6700\u5927\u8fde\u63a5\u9650\u5236\u8fc7\u4f4e\uff0c\u53ef\u4ee5\u5c06\u5176\u589e\u52a0\u5230\u66f4\u9ad8\u7684\u503c\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91 MySQL \u914d\u7f6e\u6587\u4ef6 (my.cnf) \u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\u6765\u5b8c\u6210\uff1a<\/p>\n<pre>max_connections = &lt;new_limit&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. KILL EXCESS CONNECTIONS<\/strong><\/p>\n<p>\u53ef\u4ee5\u6740\u6b7b\u8d85\u8fc7\u6700\u5927\u8fde\u63a5\u9650\u5236\u7684\u4efb\u4f55\u6d3b\u52a8\u8fde\u63a5\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a<\/p>\n<pre>kill &lt;connection_id&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u627e\u5230\u8fde\u63a5 ID\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>show processlist;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. LIMIT CONNECTIONS PER USER<\/strong><\/p>\n<p>\u53ef\u4ee5\u9650\u5236\u6bcf\u4e2a\u7528\u6237\u53ef\u4ee5\u62e5\u6709\u7684\u6700\u5927\u8fde\u63a5\u6570\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a<\/p>\n<pre>CREATE USER &lt;user_name&gt; WITH MAX_USER_CONNECTIONS &lt;max_limit&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. OPTIMIZE DATABASE QUERIES<\/strong><\/p>\n<p>\u4f18\u5316\u6570\u636e\u5e93\u67e5\u8be2\u53ef\u4ee5\u51cf\u5c11\u670d\u52a1\u5668\u7684\u8fde\u63a5\u9700\u6c42\u3002\u901a\u8fc7\u521b\u5efa\u7d22\u5f15\u3001\u4f7f\u7528\u8fde\u63a5\u6c60\u548c\u51cf\u5c11\u67e5\u8be2\u4e2d\u7684\u4e0d\u5fc5\u8981\u7684\u8fde\u63a5\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<p><strong>6. USE CONNECTION POOLS<\/strong><\/p>\n<p>\u8fde\u63a5\u6c60\u662f\u4e00\u79cd\u8f6f\u4ef6\u7ec4\u4ef6\uff0c\u5b83\u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\u7684\u6c60\u3002\u901a\u8fc7\u590d\u7528\u6c60\u4e2d\u7684\u8fde\u63a5\uff0c\u53ef\u4ee5\u51cf\u5c11\u65b0\u7684\u8fde\u63a5\u8bf7\u6c42\u3002<\/p>\n<p><strong>7. MONITOR CONNECTION USAGE<\/strong><\/p>\n<p>\u5b9a\u671f\u76d1\u89c6\u8fde\u63a5\u4f7f\u7528\u60c5\u51b5\u975e\u5e38\u91cd\u8981\uff0c\u4ee5\u68c0\u6d4b\u8fde\u63a5\u8fc7\u591a\u7684\u95ee\u9898\u5e76\u91c7\u53d6\u9002\u5f53\u63aa\u65bd\u3002\u53ef\u4ee5\u4f7f\u7528 MySQL \u7684 show processlist \u547d\u4ee4\u6216\u7b2c\u4e09\u65b9\u76d1\u63a7\u5de5\u5177\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fde\u63a5\u6570\u5360\u6ee1\u600e\u4e48\u529e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u8fde\u63a5\u8fc7\u591a\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002\u89e3\u51b3\u6b65\u9aa4\u5305\u62ec\uff1a\u627e\u51fa\u6700\u5927\u8fde\u63a5\u9650\u5236\u3002\u589e\u52a0\u8fde\u63a5\u9650\u5236\u3002\u6740\u6b7b\u8d85\u51fa\u9650\u5236\u7684\u8fde\u63a5\u3002\u9650\u5236\u6bcf\u4e2a\u7528\u6237\u8fde\u63a5\u6570\u3002\u4f18\u5316\u6570\u636e\u5e93\u67e5\u8be2\u4ee5\u51cf\u5c11\u8fde\u63a5\u3002\u4f7f\u7528\u8fde\u63a5\u6c60\u590d\u7528\u8fde\u63a5\u3002\u5b9a\u671f\u76d1\u89c6\u8fde\u63a5\u4f7f\u7528\u60c5\u51b5\u4ee5\u68c0\u6d4b\u95ee\u9898\u3002 MySQL \u8fde\u63a5\u8fc7\u591a\u95ee\u9898 \u5f53 MySQL \u8fde\u63a5\u6570\u8fc7\u591a\u65f6\uff0c\u4f1a\u4e25\u91cd\u5f71\u54cd\u6570\u636e\u5e93\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\uff1a 1. IDENTIFY THE MAXIMUM CONNECTION LIMIT \u627e\u51fa MySQL \u670d\u52a1\u5668\u7684\u5f53\u524d\u6700\u5927\u8fde\u63a5\u9650\u5236\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a show variables like &#8216;max_connections&#8217;; \u767b\u5f55\u540e\u590d\u5236 2. INCREASE THE CONNECTION LIMIT \u5982\u679c\u6700\u5927\u8fde\u63a5\u9650\u5236\u8fc7\u4f4e\uff0c\u53ef\u4ee5\u5c06\u5176\u589e\u52a0\u5230\u66f4\u9ad8\u7684\u503c\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91 MySQL \u914d\u7f6e\u6587\u4ef6 (my.cnf) \u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\u6765\u5b8c\u6210\uff1a max_connections = &lt;new_limit&gt; \u767b\u5f55\u540e\u590d\u5236 3. KILL EXCESS CONNECTIONS \u53ef\u4ee5\u6740\u6b7b\u8d85\u8fc7\u6700\u5927\u8fde\u63a5\u9650\u5236\u7684\u4efb\u4f55\u6d3b\u52a8\u8fde\u63a5\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a kill &lt;connection_id&gt;; \u767b\u5f55\u540e\u590d\u5236 \u8981\u627e\u5230\u8fde\u63a5 ID\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a show processlist; \u767b\u5f55\u540e\u590d\u5236 4. LIMIT CONNECTIONS PER USER \u53ef\u4ee5\u9650\u5236\u6bcf\u4e2a\u7528\u6237\u53ef\u4ee5\u62e5\u6709\u7684\u6700\u5927\u8fde\u63a5\u6570\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a CREATE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5481","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5481"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5481\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}