{"id":39800,"date":"2024-11-26T10:45:36","date_gmt":"2024-11-26T02:45:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39800\/"},"modified":"2024-11-26T10:45:36","modified_gmt":"2024-11-26T02:45:36","slug":"%e4%bc%98%e5%8c%96mysql%e7%9a%843%e4%b8%aa%e5%b0%8f%e7%a7%98%e8%af%80","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39800\/","title":{"rendered":"\u4f18\u5316MySQL\u76843\u4e2a\u5c0f\u79d8\u8bc0"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173068040533804.jpg\" class=\"aligncenter\" title=\"\u4f18\u5316MySQL\u76843\u4e2a\u5c0f\u79d8\u8bc0\u63d2\u56fe\" alt=\"\u4f18\u5316MySQL\u76843\u4e2a\u5c0f\u79d8\u8bc0\u63d2\u56fe\" \/><\/p>\n<p>  \u5982\u679c\u4f60\u4e0d\u6539\u53d8 MySQL \u7684\u7f3a\u7701\u914d\u7f6e\uff0c\u4f60\u7684\u670d\u52a1\u5668\u7684\u6027\u80fd\u5c31\u50cf\u9898\u56fe\u7684\u574f\u5728\u4e00\u6863\u7684\u6cd5\u62c9\u5229\u4e00\u6837 \u201c\u864e\u843d\u5e73\u9633\u88ab\u72ac\u6b3a\u201d\u3002   \u6211\u5e76\u4e0d\u671f\u671b\u6210\u4e3a\u4e00\u4e2a\u4e13\u5bb6\u7ea7\u7684 DBA\uff0c\u4f46\u662f\uff0c\u5728\u6211\u4f18\u5316 MySQL \u65f6\uff0c\u6211\u63a8\u5d07 80\/20 \u539f\u5219\uff0c\u660e\u786e\u8bf4\u5c31\u662f\u901a\u8fc7\u7b80\u5355\u7684\u8c03\u6574\u4e00\u4e9b\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u538b\u69a8\u51fa\u9ad8\u8fbe 80% \u7684\u6027\u80fd\u63d0\u5347\u3002\u5c24\u5176\u662f\u5728\u670d\u52a1\u5668\u8d44\u6e90\u8d8a\u6765\u8d8a\u4fbf\u5b9c\u7684\u5f53\u4e0b\u3002    \u8b66\u544a   1.\u6ca1\u6709\u4e24\u4e2a\u6570\u636e\u5e93\u6216\u8005\u5e94\u7528\u7a0b\u5e8f\u662f\u5b8c\u5168\u76f8\u540c\u7684\u3002\u8fd9\u91cc\u5047\u8bbe\u6211\u4eec\u8981\u8c03\u6574\u7684\u6570\u636e\u5e93\u662f\u4e3a\u4e00\u4e2a\u201c\u5178\u578b\u201d\u7684 Web \u7f51\u7ad9\u670d\u52a1\u7684\uff0c\u4f18\u5148\u8003\u8651\u7684\u662f\u5feb\u901f\u67e5\u8be2\u3001\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u4ee5\u53ca\u5904\u7406\u5927\u91cf\u7684\u6d41\u91cf\u3002   2.\u5728\u4f60\u5bf9\u670d\u52a1\u5668\u8fdb\u884c\u4f18\u5316\u4e4b\u524d\uff0c\u8bf7\u505a\u597d\u6570\u636e\u5e93\u5907\u4efd\uff01<br \/>\n<strong>1\u3001\u4f7f\u7528 InnoDB \u5b58\u50a8\u5f15\u64ce<\/strong>   \u5982\u679c\u4f60\u8fd8\u5728\u4f7f\u7528 MyISAM \u5b58\u50a8\u5f15\u64ce\uff0c\u90a3\u4e48\u662f\u65f6\u5019\u8f6c\u6362\u5230 InnoDB \u4e86\u3002\u6709\u5f88\u591a\u7684\u7406\u7531\u90fd\u8868\u660e InnoDB \u6bd4 MyISAM \u66f4\u6709\u4f18\u52bf\uff0c\u5982\u679c\u4f60\u5173\u6ce8\u6027\u80fd\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5b83\u4eec\u662f\u5982\u4f55\u5229\u7528\u7269\u7406\u5185\u5b58\u7684\uff1a   MyISAM\uff1a\u4ec5\u5728\u5185\u5b58\u4e2d\u4fdd\u5b58\u7d22\u5f15\u3002   InnoDB\uff1a\u5728\u5185\u5b58\u4e2d\u4fdd\u5b58\u7d22\u5f15\u548c\u6570\u636e\u3002   \u7ed3\u8bba\uff1a\u4fdd\u5b58\u5728\u5185\u5b58\u7684\u5185\u5bb9\u8bbf\u95ee\u901f\u5ea6\u8981\u6bd4\u78c1\u76d8\u4e0a\u7684\u66f4\u5feb\u3002   \u4e0b\u9762\u662f\u5982\u4f55\u5728\u4f60\u7684\u8868\u4e0a\u53bb\u8f6c\u6362\u5b58\u50a8\u5f15\u64ce\u7684\u547d\u4ee4\uff1a   ALTER TABLE table_name ENGINE=InnoDB;   \u6ce8\u610f\uff1a\u4f60\u5df2\u7ecf\u521b\u5efa\u4e86\u6240\u6709\u5408\u9002\u7684\u7d22\u5f15\uff0c\u5bf9\u5417\uff1f\u4e3a\u4e86\u66f4\u597d\u7684\u6027\u80fd\uff0c\u521b\u5efa\u7d22\u5f15\u6c38\u8fdc\u662f\u7b2c\u4e00\u4f18\u5148\u8003\u8651\u7684\u4e8b\u60c5\u3002<br \/>\n<strong>2\u3001\u8ba9 InnoDB \u4f7f\u7528\u6240\u6709\u7684\u5185\u5b58<\/strong>   \u4f60\u53ef\u4ee5\u5728 my.cnf \u6587\u4ef6\u4e2d\u7f16\u8f91\u4f60\u7684 MySQL \u914d\u7f6e\u3002\u4f7f\u7528 innodb_buffer_pool_size \u53c2\u6570\u53bb\u914d\u7f6e\u5728\u4f60\u7684\u670d\u52a1\u5668\u4e0a\u5141\u8bb8 InnoDB \u4f7f\u7528\u7269\u7406\u5185\u5b58\u6570\u91cf\u3002   \u5bf9\u6b64\uff08\u5047\u8bbe\u4f60\u7684\u670d\u52a1\u5668\u4ec5\u4ec5\u8fd0\u884c MySQL\uff09\uff0c\u516c\u8ba4\u7684\u201c\u7ecf\u9a8c\u6cd5\u5219\u201d\u662f\u8bbe\u7f6e\u4e3a\u4f60\u7684\u670d\u52a1\u5668\u7269\u7406\u5185\u5b58\u7684 80%\u3002\u5728\u4fdd\u8bc1\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u800c\u6b63\u5e38\u8fd0\u884c\u6240\u9700\u8981\u7684\u8db3\u591f\u5185\u5b58\u4e4b\u540e \uff0c\u5c3d\u53ef\u80fd\u591a\u5730\u4e3a MySQL \u5206\u914d\u7269\u7406\u5185\u5b58\u3002   \u56e0\u6b64\uff0c\u5982\u679c\u4f60\u7684\u670d\u52a1\u5668\u7269\u7406\u5185\u5b58\u662f 32 GB\uff0c\u53ef\u4ee5\u5c06\u90a3\u4e2a\u53c2\u6570\u8bbe\u7f6e\u4e3a\u591a\u8fbe 25 GB\u3002   innodb_buffer_pool_size = 25600M   \u6ce8\u610f\uff1a\uff081\uff09\u5982\u679c\u4f60\u7684\u670d\u52a1\u5668\u5185\u5b58\u8f83\u5c0f\u5e76\u4e14\u5c0f\u4e8e 1 GB\u3002\u4e3a\u4e86\u9002\u7528\u672c\u6587\u7684\u65b9\u6cd5\uff0c\u4f60\u5e94\u8be5\u53bb\u5347\u7ea7\u4f60\u7684\u670d\u52a1\u5668\u3002 \uff082\uff09 \u5982\u679c\u4f60\u7684\u670d\u52a1\u5668\u5185\u5b58\u7279\u522b\u5927\uff0c\u6bd4\u5982\uff0c\u5b83\u6709 200 GB\uff0c\u90a3\u4e48\uff0c\u6839\u636e\u4e00\u822c\u5e38\u8bc6\uff0c\u4f60\u4e5f\u6ca1\u6709\u5fc5\u8981\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u4fdd\u7559\u591a\u8fbe 40 GB \u7684\u5185\u5b58\u3002<br \/>\n<strong>3\u3001\u8ba9 InnoDB \u591a\u4efb\u52a1\u8fd0\u884c<\/strong>   \u5982\u679c\u670d\u52a1\u5668\u4e0a\u7684\u53c2\u6570 innodb_buffer_pool_size \u7684\u914d\u7f6e\u662f\u5927\u4e8e 1 GB\uff0c\u5c06\u6839\u636e\u53c2\u6570 innodb_buffer_pool_instances \u7684\u8bbe\u7f6e\uff0c \u5c06 InnoDB \u7684\u7f13\u51b2\u6c60\u5212\u5206\u4e3a\u591a\u4e2a\u3002   \u62e5\u6709\u591a\u4e8e\u4e00\u4e2a\u7684\u7f13\u51b2\u6c60\u7684\u597d\u5904\u6709\uff1a   \u5728\u591a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u7f13\u51b2\u6c60\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u74f6\u9888\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u542f\u7528\u591a\u7f13\u51b2\u6c60\u6765\u6700\u5c0f\u5316\u8fd9\u79cd\u4e89\u7528\u60c5\u51b5\uff1a   \u5bf9\u4e8e\u7f13\u51b2\u6c60\u6570\u91cf\u7684\u5b98\u65b9\u5efa\u8bae\u662f\uff1a   \u4e3a\u4e86\u5b9e\u73b0\u6700\u4f73\u7684\u6548\u679c\uff0c\u8981\u7efc\u5408\u8003\u8651 innodb_buffer_pool_instances \u548c innodb_buffer_pool_size \u7684\u8bbe\u7f6e\uff0c\u4ee5\u786e\u4fdd\u6bcf\u4e2a\u5b9e\u4f8b\u81f3\u5c11\u6709\u4e0d\u5c0f\u4e8e 1 GB \u7684\u7f13\u51b2\u6c60\u3002   \u56e0\u6b64\uff0c\u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c\u5c06\u53c2\u6570 innodb_buffer_pool_size \u8bbe\u7f6e\u4e3a 25 GB \u7684\u62e5\u6709 32 GB \u7269\u7406\u5185\u5b58\u7684\u670d\u52a1\u5668\u4e0a\u3002\u4e00\u4e2a\u5408\u9002\u7684\u8bbe\u7f6e\u4e3a 25600M \/ 24 = 1.06 GB   innodb_buffer_pool_instances = 24    \u6ce8\u610f   \u5728\u4fee\u6539\u4e86 my.cnf \u6587\u4ef6\u540e\u9700\u8981\u91cd\u542f MySQL \u624d\u80fd\u751f\u6548\uff1a   sudo service mysql restart   \u8fd8\u6709\u66f4\u591a\u66f4\u79d1\u5b66\u7684\u65b9\u6cd5\u6765\u4f18\u5316\u8fd9\u4e9b\u53c2\u6570\uff0c\u4f46\u662f\u8fd9\u51e0\u70b9\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u901a\u7528\u51c6\u5219\u6765\u5e94\u7528\uff0c\u5c06\u4f7f\u4f60\u7684 MySQL \u670d\u52a1\u5668\u6027\u80fd\u66f4\u597d\u3002    <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f18\u5316MySQL\u76843\u4e2a\u5c0f\u79d8\u8bc0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u4e0d\u6539\u53d8 MySQL \u7684\u7f3a\u7701\u914d\u7f6e\uff0c\u4f60\u7684\u670d\u52a1\u5668\u7684\u6027\u80fd\u5c31\u50cf\u9898\u56fe\u7684\u574f\u5728\u4e00\u6863\u7684\u6cd5\u62c9\u5229\u4e00\u6837 \u201c\u864e\u843d\u5e73\u9633\u88ab\u72ac\u6b3a\u201d\u3002 \u6211\u5e76\u4e0d\u671f\u671b\u6210\u4e3a\u4e00\u4e2a\u4e13\u5bb6\u7ea7\u7684 DBA\uff0c\u4f46\u662f\uff0c\u5728\u6211\u4f18\u5316 MySQL \u65f6\uff0c\u6211\u63a8\u5d07 80\/20 \u539f\u5219\uff0c\u660e\u786e\u8bf4\u5c31\u662f\u901a\u8fc7\u7b80\u5355\u7684\u8c03\u6574\u4e00\u4e9b\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u538b\u69a8\u51fa\u9ad8\u8fbe 80% \u7684\u6027\u80fd\u63d0\u5347\u3002\u5c24\u5176\u662f\u5728\u670d\u52a1\u5668\u8d44\u6e90\u8d8a\u6765\u8d8a\u4fbf\u5b9c\u7684\u5f53\u4e0b\u3002 \u8b66\u544a 1.\u6ca1\u6709\u4e24\u4e2a\u6570\u636e\u5e93\u6216\u8005\u5e94\u7528\u7a0b\u5e8f\u662f\u5b8c\u5168\u76f8\u540c\u7684\u3002\u8fd9\u91cc\u5047\u8bbe\u6211\u4eec\u8981\u8c03\u6574\u7684\u6570\u636e\u5e93\u662f\u4e3a\u4e00\u4e2a\u201c\u5178\u578b\u201d\u7684 Web \u7f51\u7ad9\u670d\u52a1\u7684\uff0c\u4f18\u5148\u8003\u8651\u7684\u662f\u5feb\u901f\u67e5\u8be2\u3001\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u4ee5\u53ca\u5904\u7406\u5927\u91cf\u7684\u6d41\u91cf\u3002 2.\u5728\u4f60\u5bf9\u670d\u52a1\u5668\u8fdb\u884c\u4f18\u5316\u4e4b\u524d\uff0c\u8bf7\u505a\u597d\u6570\u636e\u5e93\u5907\u4efd\uff01 1\u3001\u4f7f\u7528 InnoDB \u5b58\u50a8\u5f15\u64ce \u5982\u679c\u4f60\u8fd8\u5728\u4f7f\u7528 MyISAM \u5b58\u50a8\u5f15\u64ce\uff0c\u90a3\u4e48\u662f\u65f6\u5019\u8f6c\u6362\u5230 InnoDB \u4e86\u3002\u6709\u5f88\u591a\u7684\u7406\u7531\u90fd\u8868\u660e InnoDB \u6bd4 MyISAM \u66f4\u6709\u4f18\u52bf\uff0c\u5982\u679c\u4f60\u5173\u6ce8\u6027\u80fd\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5b83\u4eec\u662f\u5982\u4f55\u5229\u7528\u7269\u7406\u5185\u5b58\u7684\uff1a MyISAM\uff1a\u4ec5\u5728\u5185\u5b58\u4e2d\u4fdd\u5b58\u7d22\u5f15\u3002 InnoDB\uff1a\u5728\u5185\u5b58\u4e2d\u4fdd\u5b58\u7d22\u5f15\u548c\u6570\u636e\u3002 \u7ed3\u8bba\uff1a\u4fdd\u5b58\u5728\u5185\u5b58\u7684\u5185\u5bb9\u8bbf\u95ee\u901f\u5ea6\u8981\u6bd4\u78c1\u76d8\u4e0a\u7684\u66f4\u5feb\u3002 \u4e0b\u9762\u662f\u5982\u4f55\u5728\u4f60\u7684\u8868\u4e0a\u53bb\u8f6c\u6362\u5b58\u50a8\u5f15\u64ce\u7684\u547d\u4ee4\uff1a ALTER TABLE table_name ENGINE=InnoDB; \u6ce8\u610f\uff1a\u4f60\u5df2\u7ecf\u521b\u5efa\u4e86\u6240\u6709\u5408\u9002\u7684\u7d22\u5f15\uff0c\u5bf9\u5417\uff1f\u4e3a\u4e86\u66f4\u597d\u7684\u6027\u80fd\uff0c\u521b\u5efa\u7d22\u5f15\u6c38\u8fdc\u662f\u7b2c\u4e00\u4f18\u5148\u8003\u8651\u7684\u4e8b\u60c5\u3002 2\u3001\u8ba9 InnoDB \u4f7f\u7528\u6240\u6709\u7684\u5185\u5b58 \u4f60\u53ef\u4ee5\u5728 my.cnf \u6587\u4ef6\u4e2d\u7f16\u8f91\u4f60\u7684 MySQL \u914d\u7f6e\u3002\u4f7f\u7528 innodb_buffer_pool_size \u53c2\u6570\u53bb\u914d\u7f6e\u5728\u4f60\u7684\u670d\u52a1\u5668\u4e0a\u5141\u8bb8 InnoDB \u4f7f\u7528\u7269\u7406\u5185\u5b58\u6570\u91cf\u3002 \u5bf9\u6b64\uff08\u5047\u8bbe\u4f60\u7684\u670d\u52a1\u5668\u4ec5\u4ec5\u8fd0\u884c MySQL\uff09\uff0c\u516c\u8ba4\u7684\u201c\u7ecf\u9a8c\u6cd5\u5219\u201d\u662f\u8bbe\u7f6e\u4e3a\u4f60\u7684\u670d\u52a1\u5668\u7269\u7406\u5185\u5b58\u7684 80%\u3002\u5728\u4fdd\u8bc1\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u800c\u6b63\u5e38\u8fd0\u884c\u6240\u9700\u8981\u7684\u8db3\u591f\u5185\u5b58\u4e4b\u540e \uff0c\u5c3d\u53ef\u80fd\u591a\u5730\u4e3a MySQL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-39800","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39800","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=39800"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39800\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}