{"id":442558,"date":"2026-04-10T12:38:35","date_gmt":"2026-04-10T04:38:35","guid":{"rendered":"https:\/\/idc.net\/help\/?p=442558"},"modified":"2026-03-28T12:41:47","modified_gmt":"2026-03-28T04:41:47","slug":"%e9%a6%99%e6%b8%afvps%e9%83%a8%e7%bd%b2mysql-8-0%ef%bc%9a%e5%ae%89%e8%a3%85%e3%80%81%e8%bf%9c%e7%a8%8b%e8%ae%bf%e9%97%ae%e9%85%8d%e7%bd%ae%e4%b8%8e%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/442558\/","title":{"rendered":"\u9999\u6e2fVPS\u90e8\u7f72MySQL 8.0\uff1a\u5b89\u88c5\u3001\u8fdc\u7a0b\u8bbf\u95ee\u914d\u7f6e\u4e0e\u6027\u80fd\u8c03\u4f18\u5b9e\u64cd"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48 MySQL \u914d\u7f6e\u6bd4\u5b89\u88c5\u66f4\u91cd\u8981\uff1f<\/h2>\n<p>MySQL \u88c5\u597d\u540e\u76f4\u63a5\u7528\uff0c\u662f\u5f88\u591a\u4eba\u7684\u4e60\u60ef\u3002\u4f46\u9ed8\u8ba4\u914d\u7f6e\u5b58\u5728\u4e24\u4e2a\u4e25\u91cd\u95ee\u9898\uff1a<strong>\u5b89\u5168\u9690\u60a3<\/strong>\uff08root \u8d26\u6237\u5f31\u5bc6\u7801\u3001\u533f\u540d\u8d26\u6237\uff09\u548c<strong>\u6027\u80fd\u95ee\u9898<\/strong>\uff08\u9ed8\u8ba4\u53c2\u6570\u4e3a\u901a\u7528\u573a\u666f\u8bbe\u8ba1\uff0c\u4e0d\u9002\u5408 VPS \u4f4e\u5185\u5b58\u73af\u5883\uff09\u3002\u672c\u6587\u8986\u76d6\u4ece\u5b89\u88c5\u5230\u8c03\u4f18\u7684\u5b8c\u6574\u6d41\u7a0b\u3002<\/p>\n<hr \/>\n<h2>\u4e00\u3001\u5b89\u88c5 MySQL 8.0<\/h2>\n<pre><code>sudo apt update\r\nsudo apt install mysql-server -y\r\n\r\n# \u9a8c\u8bc1\u5b89\u88c5\u5e76\u67e5\u770b\u7248\u672c\r\nmysql --version\r\n\r\n# \u542f\u52a8\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\r\nsudo systemctl start mysql\r\nsudo systemctl enable mysql<\/code><\/pre>\n<hr \/>\n<h2>\u4e8c\u3001\u5b89\u5168\u521d\u59cb\u5316<\/h2>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u6309\u63d0\u793a\u4f9d\u6b21\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u8bbe\u7f6e root \u5bc6\u7801\uff08\u9009\u62e9\u5f3a\u5bc6\u7801\uff09<\/li>\n<li>\u5220\u9664\u533f\u540d\u7528\u6237\uff1a<strong>Y<\/strong><\/li>\n<li>\u7981\u6b62 root \u8fdc\u7a0b\u767b\u5f55\uff1a<strong>Y<\/strong>\uff08root \u53ea\u5141\u8bb8\u672c\u5730\u767b\u5f55\uff09<\/li>\n<li>\u5220\u9664 test \u6570\u636e\u5e93\uff1a<strong>Y<\/strong><\/li>\n<li>\u91cd\u65b0\u52a0\u8f7d\u6743\u9650\u8868\uff1a<strong>Y<\/strong><\/li>\n<\/ul>\n<hr \/>\n<h2>\u4e09\u3001\u521b\u5efa\u4e1a\u52a1\u6570\u636e\u5e93\u548c\u4e13\u7528\u7528\u6237<\/h2>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<pre><code>-- \u521b\u5efa\u6570\u636e\u5e93\r\nCREATE DATABASE myapp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\r\n\r\n-- \u521b\u5efa\u4e13\u7528\u7528\u6237\uff08\u53ea\u80fd\u8bbf\u95ee\u6307\u5b9a\u6570\u636e\u5e93\uff09\r\nCREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';\r\nGRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';\r\n\r\n-- \u5982\u9700\u5141\u8bb8\u4ece\u6307\u5b9a\u8fdc\u7a0b IP \u8bbf\u95ee\uff08\u66ff\u6362\u4e3a\u5b9e\u9645 IP\uff09\r\nCREATE USER 'myapp_user'@'1.2.3.4' IDENTIFIED BY 'StrongPassword123!';\r\nGRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'1.2.3.4';\r\n\r\nFLUSH PRIVILEGES;\r\nEXIT;<\/code><\/pre>\n<hr \/>\n<h2>\u56db\u3001\u914d\u7f6e\u8fdc\u7a0b\u8bbf\u95ee\uff08\u53ef\u9009\uff09<\/h2>\n<p>\u9ed8\u8ba4 MySQL \u53ea\u76d1\u542c 127.0.0.1\uff0c\u5982\u9700\u5141\u8bb8\u8fdc\u7a0b\u8fde\u63a5\uff1a<\/p>\n<pre><code>sudo nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code><\/pre>\n<p>\u627e\u5230 <code>bind-address<\/code>\uff0c\u4fee\u6539\u4e3a\uff1a<\/p>\n<pre><code># \u76d1\u542c\u6240\u6709\u63a5\u53e3\uff08\u914d\u5408\u9632\u706b\u5899\u9650\u5236\u6765\u6e90 IP\uff09\r\nbind-address = 0.0.0.0<\/code><\/pre>\n<p>\u5728\u9632\u706b\u5899\u4e2d\u53ea\u653e\u884c\u7279\u5b9a IP \u7684 3306 \u7aef\u53e3\uff08\u5207\u52ff\u5bf9\u6240\u6709 IP \u5f00\u653e\uff09\uff1a<\/p>\n<pre><code>sudo ufw allow from \u4f60\u7684IP\u5730\u5740 to any port 3306\r\nsudo systemctl restart mysql<\/code><\/pre>\n<hr \/>\n<h2>\u4e94\u3001\u9488\u5bf9\u4f4e\u5185\u5b58 VPS \u7684\u6027\u80fd\u8c03\u4f18<\/h2>\n<pre><code>sudo nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code><\/pre>\n<p>\u6839\u636e\u5185\u5b58\u5927\u5c0f\u8c03\u6574\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<pre><code># ===== 1G \u5185\u5b58 VPS \u53c2\u8003\u914d\u7f6e =====\r\ninnodb_buffer_pool_size = 256M      # \u901a\u5e38\u8bbe\u4e3a\u53ef\u7528\u5185\u5b58\u7684 50%\u201370%\r\ninnodb_log_file_size = 64M\r\ninnodb_flush_log_at_trx_commit = 2  # \u6027\u80fd\u4f18\u5148\uff08\u975e\u91d1\u878d\u7ea7\u4e1a\u52a1\u53ef\u7528\uff09\r\ninnodb_flush_method = O_DIRECT\r\n\r\nmax_connections = 50                # \u4f4e\u5185\u5b58\u73af\u5883\u964d\u4f4e\u8fde\u63a5\u6570\r\nthread_cache_size = 8\r\ntable_open_cache = 200\r\nquery_cache_type = 0                # MySQL 8.0 \u5df2\u79fb\u9664\u67e5\u8be2\u7f13\u5b58\r\n\r\n# ===== 2G \u5185\u5b58 VPS \u53c2\u8003\u914d\u7f6e =====\r\n# innodb_buffer_pool_size = 512M\r\n# max_connections = 100\r\n\r\n# \u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7\r\nslow_query_log = 1\r\nslow_query_log_file = \/var\/log\/mysql\/slow.log\r\nlong_query_time = 1<\/code><\/pre>\n<pre><code>sudo systemctl restart mysql<\/code><\/pre>\n<hr \/>\n<h2>\u516d\u3001\u5e38\u7528\u7ba1\u7406\u547d\u4ee4<\/h2>\n<pre><code># \u67e5\u770b\u5f53\u524d\u8fde\u63a5\u6570\r\nmysql -u root -p -e \"SHOW STATUS LIKE 'Threads_connected';\"\r\n\r\n# \u67e5\u770b\u6b63\u5728\u6267\u884c\u7684\u67e5\u8be2\r\nmysql -u root -p -e \"SHOW PROCESSLIST;\"\r\n\r\n# \u67e5\u770b InnoDB \u72b6\u6001\r\nmysql -u root -p -e \"SHOW ENGINE INNODB STATUS\\G\"\r\n\r\n# \u5206\u6790\u6162\u67e5\u8be2\u65e5\u5fd7\r\nsudo mysqldumpslow -s t -t 10 \/var\/log\/mysql\/slow.log<\/code><\/pre>\n<hr \/>\n<h2>\u603b\u7ed3<\/h2>\n<p>VPS \u4e0a\u90e8\u7f72 MySQL \u7684\u5173\u952e\u6b65\u9aa4\uff1a\u5b89\u88c5 \u2192 \u5b89\u5168\u521d\u59cb\u5316 \u2192 \u521b\u5efa\u4e1a\u52a1\u4e13\u7528\u7528\u6237\uff08\u4e0d\u7528 root\uff09\u2192 \u6839\u636e\u5185\u5b58\u8c03\u6574\u6027\u80fd\u53c2\u6570 \u2192 \u5f00\u542f\u6162\u67e5\u8be2\u65e5\u5fd7\u3002\u8fd9\u5957\u6d41\u7a0b\u5b8c\u6210\u540e\uff0cMySQL \u65e2\u5b89\u5168\u53c8\u9488\u5bf9\u4f4e\u5185\u5b58\u73af\u5883\u505a\u4e86\u4f18\u5316\uff0c\u53ef\u4ee5\u7a33\u5b9a\u652f\u6491\u4e2d\u5c0f\u578b Web \u5e94\u7528\u3002<\/p>\n<p><a title=\"\u9999\u6e2f\u4e91\u670d\u52a1\u5668\" href=\"https:\/\/idc.net\/cloud-hk\/\">IDC.Net \u9999\u6e2f\u4e91\u670d\u52a1\u5668<\/a>\u548c<a title=\"\u9999\u6e2f\u72ec\u7acb\u670d\u52a1\u5668\" href=\"https:\/\/idc.net\/hk\/\">\u9999\u6e2f\u72ec\u7acb\u670d\u52a1\u5668<\/a>\u5747\u63d0\u4f9b SSD \u786c\u76d8\u4fdd\u969c MySQL I\/O \u6027\u80fd\uff0cCN2 GIA \u76f4\u8fde\u5927\u9646\uff0c\u652f\u4ed8\u5b9d\u4ed8\u6b3e\u5373\u53ef\u5f00\u901a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48 MySQL \u914d\u7f6e\u6bd4\u5b89\u88c5\u66f4\u91cd\u8981\uff1f MySQL \u88c5\u597d\u540e\u76f4\u63a5\u7528\uff0c\u662f\u5f88\u591a\u4eba\u7684\u4e60\u60ef\u3002\u4f46\u9ed8\u8ba4\u914d\u7f6e\u5b58\u5728\u4e24\u4e2a\u4e25\u91cd\u95ee\u9898\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,7038],"tags":[],"class_list":["post-442558","post","type-post","status-publish","format-standard","hentry","category-windows","category-database"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=442558"}],"version-history":[{"count":1,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442558\/revisions"}],"predecessor-version":[{"id":442559,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442558\/revisions\/442559"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=442558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=442558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=442558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}