{"id":5125,"date":"2024-11-14T08:04:28","date_gmt":"2024-11-14T00:04:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5125\/"},"modified":"2024-11-14T08:04:28","modified_gmt":"2024-11-14T00:04:28","slug":"mysql%e5%90%af%e5%8a%a8%e5%a4%aa%e6%85%a2%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5125\/","title":{"rendered":"mysql\u542f\u52a8\u592a\u6162\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  mysql \u542f\u52a8\u6162\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5\u6709\uff1a\u7981\u7528\u67e5\u8be2\u7f13\u5b58\u9650\u5236\u540c\u65f6\u8fde\u63a5\u6570\u4f7f\u7528 innodb_flush_log_at_trx_commit = 2\u589e\u52a0\u7f13\u51b2\u6c60\u5927\u5c0f\u7981\u7528\u6162\u67e5\u8be2\u65e5\u5fd7\u4f18\u5316\u5168\u6587\u7d22\u5f15\u4fee\u590d\u635f\u574f\u7684\u8868\u624b\u52a8\u5220\u9664\u4e34\u65f6\u8868\u7981\u7528\u4e0d\u5fc5\u8981\u7684\u63d2\u4ef6\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052215032675189.jpg\" class=\"aligncenter\" title=\"mysql\u542f\u52a8\u592a\u6162\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"mysql\u542f\u52a8\u592a\u6162\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u542f\u52a8\u6162\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong> MySQL \u542f\u52a8\u592a\u6162\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n<p><strong>\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><strong>1. \u5927\u91cf\u67e5\u8be2\u7f13\u5b58<\/strong><\/p>\n<ul>\n<li>\u67e5\u8be2\u7f13\u5b58\u4f1a\u5b58\u50a8\u6700\u8fd1\u6267\u884c\u8fc7\u7684\u67e5\u8be2\u3002\u5982\u679c\u542f\u7528\u5e76\u5927\u91cf\u4f7f\u7528\uff0c\u4f1a\u5bfc\u81f4\u542f\u52a8\u7f13\u6162\u3002<\/li>\n<li>\u7981\u7528\u67e5\u8be2\u7f13\u5b58\uff1asql_query_cache = OFF<\/li>\n<\/ul>\n<p><strong>2. \u5927\u91cf\u8fde\u63a5\u8bf7\u6c42<\/strong><\/p>\n<ul>\n<li>MySQL \u5728\u542f\u52a8\u65f6\u9700\u8981\u5904\u7406\u6240\u6709\u8fde\u63a5\u8bf7\u6c42\u3002\u5927\u91cf\u7684\u8fde\u63a5\u8bf7\u6c42\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002<\/li>\n<li>\u9650\u5236\u540c\u65f6\u8fde\u63a5\u6570\uff1a\u5728 my.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e max_connections\u3002<\/li>\n<\/ul>\n<p><strong>3. \u81ea\u589e\u5217\u9501\u7b49\u5f85<\/strong><\/p>\n<ul>\n<li>\u5728\u542f\u52a8\u65f6\uff0cMySQL \u4f1a\u9501\u5b9a\u81ea\u589e\u5217\u4ee5\u9632\u6b62\u6570\u636e\u635f\u574f\u3002\u5982\u679c\u8868\u4e2d\u6709\u5927\u91cf\u7684\u81ea\u589e\u5217\uff0c\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002<\/li>\n<li>\u4f7f\u7528 innodb_flush_log_at_trx_commit = 2 \u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n<p><strong>4. InnoDB \u7f13\u51b2\u6c60\u4e0d\u8db3<\/strong><\/p>\n<ul>\n<li>InnoDB \u7f13\u51b2\u6c60\u5b58\u50a8\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u3002\u5982\u679c\u5b83\u592a\u5c0f\uff0cMySQL \u9700\u8981\u4ece\u78c1\u76d8\u8bfb\u53d6\u66f4\u591a\u6570\u636e\uff0c\u4ece\u800c\u5bfc\u81f4\u542f\u52a8\u7f13\u6162\u3002<\/li>\n<li>\u589e\u52a0\u7f13\u51b2\u6c60\u5927\u5c0f\uff1ainnodb_buffer_pool_size\u3002<\/li>\n<\/ul>\n<p><strong>5. \u6162\u67e5\u8be2\u65e5\u5fd7<\/strong><\/p>\n<ul>\n<li>\u6162\u67e5\u8be2\u65e5\u5fd7\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u9608\u503c\u7684\u67e5\u8be2\u3002\u5982\u679c\u542f\u7528\uff0c\u5728\u542f\u52a8\u65f6\u4f1a\u91cd\u65b0\u89e3\u6790\u8fd9\u4e9b\u65e5\u5fd7\u4ee5\u751f\u6210\u6458\u8981\u8868\uff0c\u4ece\u800c\u5bfc\u81f4\u542f\u52a8\u7f13\u6162\u3002<\/li>\n<li>\u7981\u7528\u6162\u67e5\u8be2\u65e5\u5fd7\uff1aslow_query_log = OFF\u3002<\/li>\n<\/ul>\n<p><strong>6. \u5168\u6587\u7d22\u5f15\u672a\u4f18\u5316<\/strong><\/p>\n<ul>\n<li>\u5168\u6587\u7d22\u5f15\u4f7f\u7528\u5012\u6392\u7d22\u5f15\uff0c\u5982\u679c\u7ef4\u62a4\u4e0d\u5f53\uff0c\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002<\/li>\n<li>\u4f18\u5316\u5168\u6587\u7d22\u5f15\uff1a\u91cd\u5efa\u7d22\u5f15\u5e76\u4f7f\u7528 ft_optimize_table \u547d\u4ee4\u3002<\/li>\n<\/ul>\n<p><strong>7. \u8868\u635f\u574f<\/strong><\/p>\n<ul>\n<li>MySQL \u5728\u542f\u52a8\u65f6\u4f1a\u68c0\u67e5\u548c\u4fee\u590d\u635f\u574f\u7684\u8868\u3002\u5982\u679c\u6709\u591a\u4e2a\u635f\u574f\u7684\u8868\uff0c\u4f1a\u4e25\u91cd\u5f71\u54cd\u542f\u52a8\u65f6\u95f4\u3002<\/li>\n<li>\u4fee\u590d\u635f\u574f\u7684\u8868\uff1a\u4f7f\u7528 myisamchk \u6216 innodb_force_recovery\u3002<\/li>\n<\/ul>\n<p><strong>8. \u4e34\u65f6\u8868<\/strong><\/p>\n<ul>\n<li>\u5728\u542f\u52a8\u65f6\uff0cMySQL \u4f1a\u91cd\u65b0\u521b\u5efa\u6240\u6709\u4e34\u65f6\u8868\u3002\u5982\u679c\u6709\u4e00\u4e9b\u7279\u522b\u5927\u7684\u4e34\u65f6\u8868\uff0c\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002<\/li>\n<li>\u624b\u52a8\u5220\u9664\u4e34\u65f6\u8868\uff1a\u5728 my.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e tmp_table_size = 0\u3002<\/li>\n<\/ul>\n<p><strong>9. \u52a0\u8f7d\u63d2\u4ef6<\/strong><\/p>\n<ul>\n<li>\u52a0\u8f7d\u7684\u63d2\u4ef6\u8d8a\u591a\uff0c\u542f\u52a8\u65f6\u95f4\u8d8a\u957f\u3002<\/li>\n<li>\u7981\u7528\u4e0d\u5fc5\u8981\u7684\u63d2\u4ef6\uff1a\u5728 my.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u6ce8\u91ca\u6389\u4e0d\u9700\u8981\u7684\u63d2\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u542f\u52a8\u592a\u6162\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 \u542f\u52a8\u6162\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5\u6709\uff1a\u7981\u7528\u67e5\u8be2\u7f13\u5b58\u9650\u5236\u540c\u65f6\u8fde\u63a5\u6570\u4f7f\u7528 innodb_flush_log_at_trx_commit = 2\u589e\u52a0\u7f13\u51b2\u6c60\u5927\u5c0f\u7981\u7528\u6162\u67e5\u8be2\u65e5\u5fd7\u4f18\u5316\u5168\u6587\u7d22\u5f15\u4fee\u590d\u635f\u574f\u7684\u8868\u624b\u52a8\u5220\u9664\u4e34\u65f6\u8868\u7981\u7528\u4e0d\u5fc5\u8981\u7684\u63d2\u4ef6 MySQL \u542f\u52a8\u6162\u7684\u89e3\u51b3\u65b9\u6cd5 \u95ee\u9898\uff1a MySQL \u542f\u52a8\u592a\u6162\uff0c\u5982\u4f55\u89e3\u51b3\uff1f \u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5\uff1a 1. \u5927\u91cf\u67e5\u8be2\u7f13\u5b58 \u67e5\u8be2\u7f13\u5b58\u4f1a\u5b58\u50a8\u6700\u8fd1\u6267\u884c\u8fc7\u7684\u67e5\u8be2\u3002\u5982\u679c\u542f\u7528\u5e76\u5927\u91cf\u4f7f\u7528\uff0c\u4f1a\u5bfc\u81f4\u542f\u52a8\u7f13\u6162\u3002 \u7981\u7528\u67e5\u8be2\u7f13\u5b58\uff1asql_query_cache = OFF 2. \u5927\u91cf\u8fde\u63a5\u8bf7\u6c42 MySQL \u5728\u542f\u52a8\u65f6\u9700\u8981\u5904\u7406\u6240\u6709\u8fde\u63a5\u8bf7\u6c42\u3002\u5927\u91cf\u7684\u8fde\u63a5\u8bf7\u6c42\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002 \u9650\u5236\u540c\u65f6\u8fde\u63a5\u6570\uff1a\u5728 my.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e max_connections\u3002 3. \u81ea\u589e\u5217\u9501\u7b49\u5f85 \u5728\u542f\u52a8\u65f6\uff0cMySQL \u4f1a\u9501\u5b9a\u81ea\u589e\u5217\u4ee5\u9632\u6b62\u6570\u636e\u635f\u574f\u3002\u5982\u679c\u8868\u4e2d\u6709\u5927\u91cf\u7684\u81ea\u589e\u5217\uff0c\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002 \u4f7f\u7528 innodb_flush_log_at_trx_commit = 2 \u8bbe\u7f6e\u3002 4. InnoDB \u7f13\u51b2\u6c60\u4e0d\u8db3 InnoDB \u7f13\u51b2\u6c60\u5b58\u50a8\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u3002\u5982\u679c\u5b83\u592a\u5c0f\uff0cMySQL \u9700\u8981\u4ece\u78c1\u76d8\u8bfb\u53d6\u66f4\u591a\u6570\u636e\uff0c\u4ece\u800c\u5bfc\u81f4\u542f\u52a8\u7f13\u6162\u3002 \u589e\u52a0\u7f13\u51b2\u6c60\u5927\u5c0f\uff1ainnodb_buffer_pool_size\u3002 5. \u6162\u67e5\u8be2\u65e5\u5fd7 \u6162\u67e5\u8be2\u65e5\u5fd7\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u9608\u503c\u7684\u67e5\u8be2\u3002\u5982\u679c\u542f\u7528\uff0c\u5728\u542f\u52a8\u65f6\u4f1a\u91cd\u65b0\u89e3\u6790\u8fd9\u4e9b\u65e5\u5fd7\u4ee5\u751f\u6210\u6458\u8981\u8868\uff0c\u4ece\u800c\u5bfc\u81f4\u542f\u52a8\u7f13\u6162\u3002 \u7981\u7528\u6162\u67e5\u8be2\u65e5\u5fd7\uff1aslow_query_log = OFF\u3002 6. \u5168\u6587\u7d22\u5f15\u672a\u4f18\u5316 \u5168\u6587\u7d22\u5f15\u4f7f\u7528\u5012\u6392\u7d22\u5f15\uff0c\u5982\u679c\u7ef4\u62a4\u4e0d\u5f53\uff0c\u4f1a\u5ef6\u957f\u542f\u52a8\u65f6\u95f4\u3002 \u4f18\u5316\u5168\u6587\u7d22\u5f15\uff1a\u91cd\u5efa\u7d22\u5f15\u5e76\u4f7f\u7528 ft_optimize_table \u547d\u4ee4\u3002 7. \u8868\u635f\u574f [&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-5125","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5125","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=5125"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5125\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}