{"id":6203,"date":"2024-11-14T12:21:07","date_gmt":"2024-11-14T04:21:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6203\/"},"modified":"2024-11-14T12:21:07","modified_gmt":"2024-11-14T04:21:07","slug":"mysql%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6203\/","title":{"rendered":"mysql\u73af\u5883\u53d8\u91cf\u5982\u4f55\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u5728 mysql \u4e2d\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a\u4f7f\u7528 set \u8bed\u53e5\u52a8\u6001\u8bbe\u7f6e\u53d8\u91cf\uff08\u4ec5\u9650\u5f53\u524d\u4f1a\u8bdd\u6709\u6548\uff09\u3002\u4f7f\u7528 mysqld \u9009\u9879\u5728\u542f\u52a8\u670d\u52a1\u5668\u65f6\u8bbe\u7f6e\u53d8\u91cf\uff08\u59cb\u7ec8\u6709\u6548\uff09\u3002\u4f7f\u7528 .my.cnf \u914d\u7f6e\u6587\u4ef6\u6301\u4e45\u5730\u8bbe\u7f6e\u53d8\u91cf\uff08\u9700\u8981\u91cd\u542f\u670d\u52a1\u5668\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061513032990898.jpg\" class=\"aligncenter\" title=\"mysql\u73af\u5883\u53d8\u91cf\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" alt=\"mysql\u73af\u5883\u53d8\u91cf\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e MySQL \u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><br \/>\u73af\u5883\u53d8\u91cf\u5728 MySQL \u4e2d\u626e\u6f14\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272\uff0c\u5b83\u4eec\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u6570\u636e\u5e93\u914d\u7f6e\u5e76\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 MySQL \u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 SET \u8bed\u53e5<\/strong><br \/>\u4f60\u53ef\u4ee5\u4f7f\u7528 SET \u8bed\u53e5\u52a8\u6001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u8be5\u8bed\u53e5\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>SET variable_name = value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u8bbe\u7f6e max_connections \u53d8\u91cf\u4e3a 200\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>SET max_connections = 200;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 d \u9009\u9879<\/strong><br \/>\u4f60\u4e5f\u53ef\u4ee5\u5728\u542f\u52a8 MySQL \u670d\u52a1\u5668\u65f6\u4f7f\u7528 mysqld \u9009\u9879\u6765\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u8fd9\u4e9b\u9009\u9879\u4ee5 &#8211;variable_name=value \u7684\u5f62\u5f0f\u6307\u5b9a\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u8bbe\u7f6e datadir \u53d8\u91cf\u4e3a \/var\/lib\/mysql\/data\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u9009\u9879\uff1a<\/p>\n<pre>mysqld --datadir=\/var\/lib\/mysql\/data<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 3\uff1a\u4f7f\u7528 .my.cnf \u914d\u7f6e\u6587\u4ef6<\/strong><br \/>.my.cnf \u914d\u7f6e\u6587\u4ef6\u662f MySQL \u7684\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u5b83\u53ef\u4ee5\u7528\u6765\u6301\u4e45\u5730\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f60\u53ef\u4ee5\u5c06\u4ee5\u4e0b\u884c\u6dfb\u52a0\u5230 .my.cnf \u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre>[mysqld]\nvariable_name = value<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u8bbe\u7f6e innodb_buffer_pool_size \u53d8\u91cf\u4e3a 16GB\uff0c\u4f60\u53ef\u4ee5\u5c06\u4ee5\u4e0b\u884c\u6dfb\u52a0\u5230 .my.cnf \u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre>[mysqld]\ninnodb_buffer_pool_size = 16G<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li> <strong>\uff1a<\/strong>\u4f7f\u7528 SET \u8bed\u53e5\u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\u4ec5\u5728\u5f53\u524d\u4f1a\u8bdd\u4e2d\u6709\u6548\u3002\u4f7f\u7528 mysqld \u9009\u9879\u6216 .my.cnf \u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\u5728\u542f\u52a8 MySQL \u670d\u52a1\u5668\u540e\u59cb\u7ec8\u6709\u6548\u3002<\/li>\n<li> <strong>\u91cd\u542f\uff1a<\/strong>\u5728\u4fee\u6539\u4e86 .my.cnf \u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u9700\u8981\u91cd\u542f MySQL \u670d\u52a1\u5668\u624d\u80fd\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/li>\n<li> <strong>\u4f18\u5148\u7ea7\uff1a<\/strong>\u4f7f\u7528 mysqld \u9009\u9879\u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\u4f18\u5148\u7ea7\u6700\u9ad8\uff0c\u5176\u6b21\u662f\u4f7f\u7528 .my.cnf \u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\u7684\u53d8\u91cf\uff0c\u6700\u540e\u662f\u4f7f\u7528 SET \u8bed\u53e5\u8bbe\u7f6e\u7684\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u73af\u5883\u53d8\u91cf\u5982\u4f55\u8bbe\u7f6e\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>\u53ef\u4ee5\u5728 mysql \u4e2d\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a\u4f7f\u7528 set \u8bed\u53e5\u52a8\u6001\u8bbe\u7f6e\u53d8\u91cf\uff08\u4ec5\u9650\u5f53\u524d\u4f1a\u8bdd\u6709\u6548\uff09\u3002\u4f7f\u7528 mysqld \u9009\u9879\u5728\u542f\u52a8\u670d\u52a1\u5668\u65f6\u8bbe\u7f6e\u53d8\u91cf\uff08\u59cb\u7ec8\u6709\u6548\uff09\u3002\u4f7f\u7528 .my.cnf \u914d\u7f6e\u6587\u4ef6\u6301\u4e45\u5730\u8bbe\u7f6e\u53d8\u91cf\uff08\u9700\u8981\u91cd\u542f\u670d\u52a1\u5668\uff09\u3002 \u5982\u4f55\u8bbe\u7f6e MySQL \u73af\u5883\u53d8\u91cf \u5f15\u8a00\u73af\u5883\u53d8\u91cf\u5728 MySQL \u4e2d\u626e\u6f14\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272\uff0c\u5b83\u4eec\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u6570\u636e\u5e93\u914d\u7f6e\u5e76\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 MySQL \u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002 \u65b9\u6cd5 1\uff1a\u4f7f\u7528 SET \u8bed\u53e5\u4f60\u53ef\u4ee5\u4f7f\u7528 SET \u8bed\u53e5\u52a8\u6001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u8be5\u8bed\u53e5\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a SET variable_name = value; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u8bbe\u7f6e max_connections \u53d8\u91cf\u4e3a 200\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a SET max_connections = 200; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 d \u9009\u9879\u4f60\u4e5f\u53ef\u4ee5\u5728\u542f\u52a8 MySQL \u670d\u52a1\u5668\u65f6\u4f7f\u7528 mysqld \u9009\u9879\u6765\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u8fd9\u4e9b\u9009\u9879\u4ee5 &#8211;variable_name=value \u7684\u5f62\u5f0f\u6307\u5b9a\u3002 \u4f8b\u5982\uff0c\u8981\u8bbe\u7f6e datadir \u53d8\u91cf\u4e3a \/var\/lib\/mysql\/data\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u9009\u9879\uff1a mysqld &#8211;datadir=\/var\/lib\/mysql\/data \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 [&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-6203","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6203","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=6203"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6203\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}