{"id":189066,"date":"2024-11-12T04:17:18","date_gmt":"2024-11-11T20:17:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/189066\/"},"modified":"2024-11-12T04:17:20","modified_gmt":"2024-11-11T20:17:20","slug":"%e6%8f%90%e5%8d%87mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%80%a7%e8%83%bd%ef%bc%9a%e6%a7%8b%e5%bb%ba%e9%ab%98%e6%95%88%e7%b7%9a%e7%a8%8b%e6%b1%a0-mysql-%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b7%9a%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/189066\/","title":{"rendered":"\u63d0\u5347MySQL\u6578\u64da\u5eab\u6027\u80fd\uff1a\u69cb\u5efa\u9ad8\u6548\u7dda\u7a0b\u6c60 (mysql \u6578\u64da\u5eab\u7dda\u7a0b\u6c60)"},"content":{"rendered":"<h1 id=\"%e6%8f%90%e5%8d%87mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%80%a7%e8%83%bd%ef%bc%9a%e6%a7%8b%e5%bb%ba%e9%ab%98%e6%95%88%e7%b7%9a%e7%a8%8b%e6%b1%a0-JIoIpDYcrH\">\u63d0\u5347MySQL\u6578\u64da\u5eab\u6027\u80fd\uff1a\u69cb\u5efa\u9ad8\u6548\u7dda\u7a0b\u6c60<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6574\u9ad4\u6548\u7387\u81f3\u95dc\u91cd\u8981\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u696d\u52d9\u4e2d\u3002\u70ba\u4e86\u63d0\u5347MySQL\u7684\u6027\u80fd\uff0c\u69cb\u5efa\u9ad8\u6548\u7684\u7dda\u7a0b\u6c60\u662f\u4e00\u500b\u91cd\u8981\u7684\u7b56\u7565\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u7dda\u7a0b\u6c60\u7684\u6982\u5ff5\u3001\u5176\u5728MySQL\u4e2d\u7684\u61c9\u7528\u4ee5\u53ca\u5982\u4f55\u6709\u6548\u5730\u69cb\u5efa\u548c\u7ba1\u7406\u7dda\u7a0b\u6c60\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e7%b7%9a%e7%a8%8b%e6%b1%a0%ef%bc%9f-JIoIpDYcrH\">\u4ec0\u9ebc\u662f\u7dda\u7a0b\u6c60\uff1f<\/h2>\n<p>\u7dda\u7a0b\u6c60\u662f\u4e00\u7a2e\u8a2d\u8a08\u6a21\u5f0f\uff0c\u7528\u65bc\u7ba1\u7406\u548c\u91cd\u7528\u4e00\u7d44\u7dda\u7a0b\uff0c\u4ee5\u63d0\u9ad8\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u901a\u904e\u9810\u5148\u5275\u5efa\u4e00\u5b9a\u6578\u91cf\u7684\u7dda\u7a0b\uff0c\u7dda\u7a0b\u6c60\u53ef\u4ee5\u907f\u514d\u5728\u6bcf\u6b21\u8acb\u6c42\u6642\u5275\u5efa\u548c\u92b7\u6bc0\u7dda\u7a0b\u7684\u958b\u92b7\u3002\u9019\u6a23\u4e0d\u50c5\u80fd\u5920\u6e1b\u5c11\u8cc7\u6e90\u7684\u6d88\u8017\uff0c\u9084\u80fd\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\u3002<\/p>\n<h2 id=\"mysql%e4%b8%ad%e7%9a%84%e7%b7%9a%e7%a8%8b%e6%b1%a0-JIoIpDYcrH\">MySQL\u4e2d\u7684\u7dda\u7a0b\u6c60<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u7dda\u7a0b\u6c60\u7684\u4e3b\u8981\u76ee\u7684\u662f\u7ba1\u7406\u9023\u63a5\u8acb\u6c42\u3002\u7576\u61c9\u7528\u7a0b\u5e8f\u9700\u8981\u8a2a\u554f\u6578\u64da\u5eab\u6642\uff0c\u5b83\u6703\u5411\u7dda\u7a0b\u6c60\u8acb\u6c42\u4e00\u500b\u53ef\u7528\u7684\u7dda\u7a0b\u4f86\u8655\u7406\u8acb\u6c42\u3002\u9019\u6a23\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u540c\u6642\u9023\u63a5\u7684\u6578\u91cf\uff0c\u5f9e\u800c\u907f\u514d\u56e0\u70ba\u904e\u591a\u7684\u9023\u63a5\u800c\u5c0e\u81f4\u7684\u6027\u80fd\u4e0b\u964d\u3002<\/p>\n<h3 id=\"%e7%b7%9a%e7%a8%8b%e6%b1%a0%e7%9a%84%e5%84%aa%e5%8b%a2-JIoIpDYcrH\">\u7dda\u7a0b\u6c60\u7684\u512a\u52e2<\/h3>\n<ul>\n<li><strong>\u63d0\u9ad8\u6027\u80fd\uff1a<\/strong>\u901a\u904e\u91cd\u7528\u7dda\u7a0b\uff0c\u6e1b\u5c11\u4e86\u5275\u5efa\u548c\u92b7\u6bc0\u7dda\u7a0b\u7684\u958b\u92b7\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u7ba1\u7406\uff1a<\/strong>\u6709\u6548\u63a7\u5236\u540c\u6642\u9023\u63a5\u7684\u6578\u91cf\uff0c\u907f\u514d\u8cc7\u6e90\u6d6a\u8cbb\u3002<\/li>\n<li><strong>\u97ff\u61c9\u901f\u5ea6\uff1a<\/strong>\u6e1b\u5c11\u8acb\u6c42\u7684\u5ef6\u9072\uff0c\u63d0\u9ad8\u7528\u6236\u9ad4\u9a57\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e6%a7%8b%e5%bb%ba%e9%ab%98%e6%95%88%e7%9a%84mysql%e7%b7%9a%e7%a8%8b%e6%b1%a0-JIoIpDYcrH\">\u5982\u4f55\u69cb\u5efa\u9ad8\u6548\u7684MySQL\u7dda\u7a0b\u6c60<\/h2>\n<p>\u69cb\u5efa\u9ad8\u6548\u7684MySQL\u7dda\u7a0b\u6c60\u9700\u8981\u8003\u616e\u591a\u500b\u56e0\u7d20\uff0c\u5305\u62ec\u7dda\u7a0b\u6578\u91cf\u3001\u9023\u63a5\u7ba1\u7406\u548c\u932f\u8aa4\u8655\u7406\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff1a<\/p>\n<h3 id=\"1-%e7%a2%ba%e5%ae%9a%e7%b7%9a%e7%a8%8b%e6%95%b8%e9%87%8f-JIoIpDYcrH\">1. \u78ba\u5b9a\u7dda\u7a0b\u6578\u91cf<\/h3>\n<p>\u7dda\u7a0b\u6578\u91cf\u7684\u9078\u64c7\u61c9\u6839\u64da\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u548c\u670d\u52d9\u5668\u7684\u8cc7\u6e90\u4f86\u6c7a\u5b9a\u3002\u4e00\u822c\u4f86\u8aaa\uff0c\u7dda\u7a0b\u6578\u91cf\u61c9\u8a72\u8207CPU\u6838\u5fc3\u6578\u91cf\u76f8\u5339\u914d\uff0c\u9019\u6a23\u53ef\u4ee5\u5145\u5206\u5229\u7528\u591a\u6838\u8655\u7406\u5668\u7684\u6027\u80fd\u3002<\/p>\n<pre><code>SET GLOBAL thread_pool_size = 8; -- \u8a2d\u7f6e\u7dda\u7a0b\u6c60\u5927\u5c0f\u70ba8<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e9%80%a3%e6%8e%a5%e6%b1%a0-JIoIpDYcrH\">2. \u4f7f\u7528\u9023\u63a5\u6c60<\/h3>\n<p>\u9023\u63a5\u6c60\u662f\u4e00\u7a2e\u7ba1\u7406\u6578\u64da\u5eab\u9023\u63a5\u7684\u6280\u8853\uff0c\u53ef\u4ee5\u8207\u7dda\u7a0b\u6c60\u7d50\u5408\u4f7f\u7528\u3002\u901a\u904e\u4f7f\u7528\u9023\u63a5\u6c60\uff0c\u61c9\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u9700\u8981\u6642\u5feb\u901f\u7372\u53d6\u53ef\u7528\u7684\u6578\u64da\u5eab\u9023\u63a5\uff0c\u5f9e\u800c\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<pre><code>CREATE TABLE connection_pool (\n    id INT PRIMARY KEY AUTO_INCREMENT,\n    connection VARCHAR(255) NOT NULL\n);<\/code><\/pre>\n<h3 id=\"3-%e9%8c%af%e8%aa%a4%e8%99%95%e7%90%86-JIoIpDYcrH\">3. \u932f\u8aa4\u8655\u7406<\/h3>\n<p>\u5728\u69cb\u5efa\u7dda\u7a0b\u6c60\u6642\uff0c\u5fc5\u9808\u8003\u616e\u5230\u932f\u8aa4\u8655\u7406\u6a5f\u5236\u3002\u7576\u7dda\u7a0b\u9047\u5230\u932f\u8aa4\u6642\uff0c\u61c9\u8a72\u80fd\u5920\u81ea\u52d5\u91cd\u8a66\u6216\u5c07\u932f\u8aa4\u8a18\u9304\u5230\u65e5\u8a8c\u4e2d\uff0c\u4ee5\u4fbf\u5f8c\u7e8c\u5206\u6790\u3002<\/p>\n<pre><code>try {\n    \/\/ \u5617\u8a66\u57f7\u884c\u6578\u64da\u5eab\u64cd\u4f5c\n} catch (Exception $e) {\n    \/\/ \u8a18\u9304\u932f\u8aa4\n    error_log($e-&gt;getMessage());\n}<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-JIoIpDYcrH\">\u7d50\u8ad6<\/h2>\n<p>\u69cb\u5efa\u9ad8\u6548\u7684MySQL\u7dda\u7a0b\u6c60\u662f\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e\u7dda\u7a0b\u6578\u91cf\u3001\u4f7f\u7528\u9023\u63a5\u6c60\u4ee5\u53ca\u6709\u6548\u7684\u932f\u8aa4\u8655\u7406\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u61c9\u7528\u7a0b\u5e8f\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u8cc7\u6e90\u5229\u7528\u7387\u3002\u96a8\u8457\u696d\u52d9\u9700\u6c42\u7684\u589e\u9577\uff0c\u6301\u7e8c\u76e3\u63a7\u548c\u8abf\u6574\u7dda\u7a0b\u6c60\u7684\u914d\u7f6e\u5c07\u6709\u52a9\u65bc\u4fdd\u6301\u6578\u64da\u5eab\u7684\u9ad8\u6548\u904b\u884c\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684MySQL\u6578\u64da\u5eab\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u63d0\u5347\u696d\u52d9\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63d0\u5347MySQL\u6578\u64da\u5eab\u6027\u80fd\uff0c\u5b78\u7fd2\u5982\u4f55\u69cb\u5efa\u9ad8\u6548\u7dda\u7a0b\u6c60\uff0c\u512a\u5316\u67e5\u8a62\u901f\u5ea6\uff0c\u6e1b\u5c11\u5ef6\u9072\uff0c\u5be6\u73fe\u66f4\u9ad8\u7684\u6578\u64da\u8655\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-189066","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=189066"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189066\/revisions"}],"predecessor-version":[{"id":189067,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189066\/revisions\/189067"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=189066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=189066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=189066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}