{"id":258285,"date":"2022-12-24T09:16:22","date_gmt":"2022-12-24T01:16:22","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=258285"},"modified":"2022-11-29T10:17:20","modified_gmt":"2022-11-29T02:17:20","slug":"mysql-cnf-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-cnf-linux.html","title":{"rendered":"\u89e3\u6790MySQL \u914d\u7f6e\u6587\u4ef6 my.cnf \/ my.ini \u533a\u522b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5145\u5206\u7406\u89e3 MySQL \u914d\u7f6e\u6587\u4ef6\u4e2d\u5404\u4e2a\u53d8\u91cf\u7684\u610f\u4e49\u5bf9\u6211\u4eec\u6709\u9488\u5bf9\u6027\u7684\u4f18\u5316 MySQL \u6570\u636e\u5e93\u6027\u80fd\u6709\u975e\u5e38\u5927\u7684\u610f\u4e49\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86MySQL \u914d\u7f6e\u6587\u4ef6 my.cnf \/ my.ini \u533a\u522b,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5145\u5206\u7406\u89e3 MySQL \u914d\u7f6e\u6587\u4ef6\u4e2d\u5404\u4e2a\u53d8\u91cf\u7684\u610f\u4e49\u5bf9\u6211\u4eec\u6709\u9488\u5bf9\u6027\u7684\u4f18\u5316 MySQL \u6570\u636e\u5e93\u6027\u80fd\u6709\u975e\u5e38\u5927\u7684\u610f\u4e49\u3002\u6211\u4eec\u9700\u8981\u6839\u636e\u4e0d\u540c\u7684\u6570\u636e\u91cf\u7ea7\uff0c\u4e0d\u540c\u7684\u751f\u4ea7\u73af\u5883\u60c5\u51b5\u5bf9 MySQL \u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n

\u4e00\u3001\u914d\u7f6e\u6587\u4ef6my.ini\u6216my.cnf\u7684\u4f4d\u7f6e<\/strong><\/div>\n

Windows \u548c Linux \u4e0b\u7684 MySQL \u914d\u7f6e\u6587\u4ef6\u7684\u540d\u5b57\u548c\u5b58\u653e\u4f4d\u7f6e\u90fd\u662f\u4e0d\u540c\u7684\uff1a<\/p>\n

1\u3001WIndows \u4e0b MySQL \u914d\u7f6e\u6587\u4ef6\u662f my.ini \u5b58\u653e\u5728 MySQL \u5b89\u88c5\u76ee\u5f55\u7684\u6839\u76ee\u5f55\u4e0b\uff1b<\/p>\n

2\u3001Linux \u4e0b MySQL \u914d\u7f6e\u6587\u4ef6\u662f my.cnf \u5b58\u653e\u5728 \/etc\/my.cnf\u3001\/etc\/mysql\/my.cnf\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7 find \u547d\u4ee4\u8fdb\u884c\u67e5\u627e\u3002<\/p>\n

1)find \/etc -name my.cnf\u3000\u3000 --\u5728\/etc\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6my.cnf\r\n\u30002)find \/etc -name '*cnf*'\u3000\u3000--\u4f7f\u7528\u901a\u914d\u7b26*(0\u6216\u8005\u4efb\u610f\u591a\u4e2a)\u3002\u8868\u793a\u5728\/etc\u76ee\u5f55\u4e0b\u67e5\u627e\u6587\u4ef6\u540d\u4e2d\u542b\u6709\u5b57\u7b26\u4e32\u2018cnf'\u7684\u6587\u4ef6\r\n\u30003)find \/ -name my.cnf\u3000\u3000    --\u5728\u6839\u76ee\u5f55\u4e0b\u67e5\u627e\u6587\u4ef6my.cnf\uff0c\u8868\u793a\u5728\u6574\u4e2a\u786c\u76d8\u67e5\u627e\r\n\u30004)find . -name 'cnf*' \u3000\u3000   --\u8868\u793a\u5f53\u524d\u76ee\u5f55\u4e0b\u67e5\u627e\u6587\u4ef6\u540d\u5f00\u5934\u662f\u5b57\u7b26\u4e32\u2018cnf'\u7684\u6587\u4ef6<\/pre>\n

3\u3001\u53e6\u5916\u8981\u6ce8\u610f\u7684\u662f\uff0cLinux\u7528rpm\u5305\u5b89\u88c5\u7684MySQL\u662f\u4e0d\u4f1a\u5b89\u88c5\/etc\/my.cnf\u6587\u4ef6\u7684\u3002<\/p>\n

\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6\u800cMySQL\u5374\u4e5f\u80fd\u6b63\u5e38\u542f\u52a8\u548c\u4f5c\u7528\uff0c\u6709\u4e24\u4e2a\u8bf4\u6cd5\uff1a<\/p>\n

\u7b2c\u4e00\u79cd\u8bf4\u6cd5\uff0cmy.cnf\u53ea\u662fMySQL\u542f\u52a8\u65f6\u7684\u4e00\u4e2a\u53c2\u6570\u6587\u4ef6\uff0c\u53ef\u4ee5\u6ca1\u6709\u5b83\uff0c\u8fd9\u65f6MySQL\u4f1a\u7528\u5185\u7f6e\u7684\u9ed8\u8ba4\u53c2\u6570\u542f\u52a8\uff1b<\/p>\n

\u7b2c\u4e8c\u79cd\u8bf4\u6cd5\uff0cMySQL\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u4f7f\u7528\/usr\/share\/mysql\u76ee\u5f55\u4e0b\u7684my-medium.cnf\u6587\u4ef6\uff0c\u8fd9\u79cd\u8bf4\u6cd5\u4ec5\u9650\u4e8erpm\u5305\u5b89\u88c5\u7684MySQL\u3002<\/p>\n

\u89e3\u51b3\u65b9\u6cd5\uff1a\u53ea\u9700\u8981\u590d\u5236\u4e00\u4e2a\/usr\/share\/mysql\u76ee\u5f55\u4e0b\u7684.cnf\u6587\u4ef6\u5230\/etc\u76ee\u5f55\uff0c\u5e76\u6539\u540d\u4e3amy.cnf\u5373\u53ef\u3002<\/p>\n

\u4e8c\u3001\u914d\u7f6e\u6587\u4ef6my.cnf\u7684\u5185\u5bb9\u8be6\u89e3<\/strong><\/div>\n
[mysqld]\r\n# \u6307\u5b9aMysql\u6570\u636e\u5e93\u7684\u5f00\u653e\u7aef\u53e3\u3002\r\nport = 3306\r\n# \u8bbe\u7f6eMysql\u6570\u636e\u5e93\u7684\u5b89\u88c5\u76ee\u5f55(\u7edd\u5bf9\u8def\u5f84)\u3002\r\nbasedir = \/usr\/local\/mysql\r\n# \u8bbe\u7f6eMysql\u6570\u636e\u5e93\u7684\u6570\u636e\u5b58\u653e\u7684\u7edd\u5bf9\u8def\u5f84(\u5b58\u653e\u76ee\u5f55)\u3002\u5fc5\u987b\u662fdata,\u6216\u8005\u662f\\\\xxx-data(my.ini\u9700\u8981,my.cnf\u4e0d\u9700\u8981)\u3002\r\ndatadir = \/www\/server\/data\r\n# \u8bbe\u7f6eMySQL\u6570\u636e\u5e93\u7684\u6700\u5927\u8fde\u63a5\u6570\u91cf\u3002\u5982\u679c\u670d\u52a1\u5668\u7684\u5e76\u53d1\u8fde\u63a5\u8bf7\u6c42\u91cf\u6bd4\u8f83\u5927\uff0c\u5efa\u8bae\u8c03\u9ad8\u6b64\u503c\uff0c\u4ee5\u589e\u52a0\u5e76\u884c\u8fde\u63a5\u6570\u91cf\u3002\u53ef\u4ee5\u8fc7'%connect%'\u901a\u914d\u7b26\u67e5\u770b\u5f53\u524d\u72b6\u6001\u7684\u8fde\u63a5\u6570\u91cf\uff0c\u4ee5\u5b9a\u593a\u8be5\u503c\u7684\u5927\u5c0f\u3002\r\nmax_connections = 100\r\n# \u8bbe\u7f6eMySQL\u6570\u636e\u5e93\u7684\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u3002\u9ed8\u8ba4\u8bbe\u7f6e\u662f\u4e00\u4e2a\u6570\u636e\u5e93\u8fde\u63a5\u8d85\u8fc78\u5c0f\u65f6\u6ca1\u6709\u4f7f\u7528,\u8fbe\u5230\u4e86server\u7aef\u7684timeout,\u670d\u52a1\u5668\u5c06\u65ad\u5f00\u8fd9\u6761\u8fde\u63a5,\u6b64\u540e\u518d\u901a\u8fc7\u8fd9\u4e2aconnection\u53d1\u8d77\u67e5\u8be2\u64cd\u4f5c\u90fd\u5c06\u5931\u8d25\u3002\u8d85\u65f6\u7b49\u5f85\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\uff0c\u5373\u4e00\u4e2aconnection\u5728\u82e5\u5e72\u79d2\u5185\u65e0\u54cd\u5e94\uff0c\u5219\u670d\u52a1\u5668\u5207\u65ad\u4e0e\u8fd9\u4e2a\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u3002\r\nwait_timeout = 28800\r\n# \u5f53\u6ca1\u6709\u6570\u636e\u5e93\u8bf7\u6c42\u65f6\uff0c28800\u79d2\uff08\u53738\u5c0f\u65f6\uff09\u5c06\u81ea\u52a8\u65ad\u5f00\u8fde\u63a5\u3002\u8981\u540c\u65f6\u8bbe\u7f6einteractive_timeout\u548cwait_timeout\u624d\u4f1a\u751f\u6548\u3002\r\ninteractive_timeout = 28800<\/pre>\n

\u200b<\/p>\n

\u4e09\u3001\u914d\u7f6e\u6587\u4ef6my.cnf\u7684\u5185\u5bb9\u67e5\u627e<\/strong><\/div>\n
# \u67e5\u770b\u5e76\u53d1\u6570\r\nmysql> show status like 'Threads%';\r\n# \u67e5\u770bmysql\u670d\u52a1\u5668\u7684\u6700\u5927\u8fde\u63a5\u6570\u503c\r\nmysql> show variables like '%max_connections%';\r\n# \u67e5\u770bmysql\u670d\u52a1\u5668\u54cd\u5e94\u7684\u6700\u5927\u8fde\u63a5\u6570:\r\nmysql> show global status like 'Max_used_connections';<\/pre>\n
\u56db\u3001\u914d\u7f6e\u6587\u4ef6my.cnf\u7684\u5185\u5bb9\u4fee\u6539<\/strong><\/div>\n
# \u8bbe\u7f6emysql\u670d\u52a1\u5668\u7684\u6700\u5927\u8fde\u63a5\u6570\u503c\r\nmysql> set GLOBAL max_connections=256;<\/pre>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eMySQL \u914d\u7f6e\u6587\u4ef6 my.cnf \/ my.ini \u533a\u522b\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5145\u5206\u7406\u89e3 MySQL \u914d\u7f6e\u6587\u4ef6\u4e2d\u5404\u4e2a\u53d8\u91cf\u7684\u610f\u4e49\u5bf9\u6211\u4eec\u6709\u9488\u5bf9\u6027\u7684\u4f18\u5316 MySQL \u6570\u636e\u5e93\u6027\u80fd\u6709\u975e\u5e38\u5927\u7684\u610f\u4e49\u3002\u6211\u4eec […]<\/p>\n","protected":false},"author":1479,"featured_media":11367,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-258285","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/258285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=258285"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/258285\/revisions"}],"predecessor-version":[{"id":258289,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/258285\/revisions\/258289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/11367"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=258285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=258285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=258285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}