{"id":52431,"date":"2024-10-09T02:35:16","date_gmt":"2024-10-08T18:35:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/52431\/"},"modified":"2024-11-14T10:38:56","modified_gmt":"2024-11-14T02:38:56","slug":"ubuntu-%e9%87%8d%e6%96%b0%e5%ae%89%e8%a3%9d-mysql-%e9%8c%af%e8%aa%a4%e8%a7%a3%e6%b1%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/52431\/","title":{"rendered":"Ubuntu \u91cd\u65b0\u5b89\u88dd MySQL \u932f\u8aa4\u89e3\u6c7a"},"content":{"rendered":"<h1 id=\"ubuntu-%e9%87%8d%e6%96%b0%e5%ae%89%e8%a3%9d-mysql-%e9%8c%af%e8%aa%a4%e8%a7%a3%e6%b1%ba-xPswZxSpkC\">Ubuntu \u91cd\u65b0\u5b89\u88dd MySQL \u932f\u8aa4\u89e3\u6c7a<\/h1>\n<p>\u5728\u4f7f\u7528 Ubuntu \u7cfb\u7d71\u6642\uff0cMySQL \u662f\u4e00\u500b\u975e\u5e38\u6d41\u884c\u7684\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\u3002\u7136\u800c\uff0c\u5728\u91cd\u65b0\u5b89\u88dd MySQL \u7684\u904e\u7a0b\u4e2d\uff0c\u4f7f\u7528\u8005\u53ef\u80fd\u6703\u9047\u5230\u5404\u7a2e\u932f\u8aa4\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\uff0c\u5e6b\u52a9\u4f7f\u7528\u8005\u9806\u5229\u5b8c\u6210 MySQL \u7684\u91cd\u65b0\u5b89\u88dd\u3002<\/p>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e9%8c%af%e8%aa%a4%e5%8f%8a%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-xPswZxSpkC\">\u5e38\u898b\u932f\u8aa4\u53ca\u89e3\u6c7a\u65b9\u6848<\/h2>\n<h3 id=\"1-mysql-%e6%9c%8d%e5%8b%99%e6%9c%aa%e8%83%bd%e5%95%9f%e5%8b%95-xPswZxSpkC\">1. MySQL \u670d\u52d9\u672a\u80fd\u555f\u52d5<\/h3>\n<p>\u5728\u91cd\u65b0\u5b89\u88dd MySQL \u5f8c\uff0c\u6700\u5e38\u898b\u7684\u554f\u984c\u4e4b\u4e00\u662f MySQL \u670d\u52d9\u7121\u6cd5\u555f\u52d5\u3002\u9019\u53ef\u80fd\u662f\u7531\u65bc\u914d\u7f6e\u6587\u4ef6\u932f\u8aa4\u6216\u7aef\u53e3\u885d\u7a81\u9020\u6210\u7684\u3002<\/p>\n<ul>\n<li><strong>\u6aa2\u67e5\u914d\u7f6e\u6587\u4ef6\uff1a<\/strong>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 MySQL \u7684\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u65bc \/etc\/mysql\/my.cnf\uff09\u662f\u5426\u6b63\u78ba\u3002<\/li>\n<pre><code>sudo nano \/etc\/mysql\/my.cnf<\/code><\/pre>\n<li><strong>\u67e5\u770b\u65e5\u8a8c\u6587\u4ef6\uff1a<\/strong>\u6aa2\u67e5 MySQL \u7684\u65e5\u8a8c\u6587\u4ef6\u4ee5\u7372\u53d6\u66f4\u591a\u932f\u8aa4\u4fe1\u606f\uff0c\u65e5\u8a8c\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc \/var\/log\/mysql\/error.log\u3002<\/li>\n<pre><code>sudo tail -f \/var\/log\/mysql\/error.log<\/code><\/pre>\n<li><strong>\u6aa2\u67e5\u7aef\u53e3\uff1a<\/strong>\u78ba\u4fdd MySQL \u4f7f\u7528\u7684\u7aef\u53e3\uff08\u9ed8\u8a8d\u70ba 3306\uff09\u672a\u88ab\u5176\u4ed6\u670d\u52d9\u4f54\u7528\u3002<\/li>\n<\/ul>\n<h3 id=\"2-%e8%b3%87%e6%96%99%e5%ba%ab%e7%84%a1%e6%b3%95%e9%80%a3%e6%8e%a5-xPswZxSpkC\">2. \u8cc7\u6599\u5eab\u7121\u6cd5\u9023\u63a5<\/h3>\n<p>\u5728\u91cd\u65b0\u5b89\u88dd MySQL \u5f8c\uff0c\u4f7f\u7528\u8005\u53ef\u80fd\u6703\u9047\u5230\u7121\u6cd5\u9023\u63a5\u5230\u8cc7\u6599\u5eab\u7684\u60c5\u6cc1\u3002\u9019\u901a\u5e38\u662f\u7531\u65bc\u7528\u6236\u6b0a\u9650\u6216\u9632\u706b\u7246\u8a2d\u7f6e\u554f\u984c\u5f15\u8d77\u7684\u3002<\/p>\n<ul>\n<li><strong>\u6aa2\u67e5\u7528\u6236\u6b0a\u9650\uff1a<\/strong>\u78ba\u4fdd\u60a8\u4f7f\u7528\u7684 MySQL \u7528\u6236\u64c1\u6709\u6b63\u78ba\u7684\u6b0a\u9650\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u7528\u6236\u6b0a\u9650\uff1a<\/li>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<li><strong>\u6aa2\u67e5\u9632\u706b\u7246\u8a2d\u7f6e\uff1a<\/strong>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f UFW \u9632\u706b\u7246\uff0c\u8acb\u78ba\u4fdd MySQL \u7684\u7aef\u53e3\u5df2\u958b\u653e\uff1a<\/li>\n<pre><code>sudo ufw allow 3306<\/code><\/pre>\n<\/ul>\n<h3 id=\"3-%e5%ae%89%e8%a3%9d%e9%81%8e%e7%a8%8b%e4%b8%ad%e7%9a%84%e4%be%9d%e8%b3%b4%e5%95%8f%e9%a1%8c-xPswZxSpkC\">3. \u5b89\u88dd\u904e\u7a0b\u4e2d\u7684\u4f9d\u8cf4\u554f\u984c<\/h3>\n<p>\u5728\u5b89\u88dd MySQL \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4f9d\u8cf4\u554f\u984c\uff0c\u9019\u901a\u5e38\u662f\u7531\u65bc\u7cfb\u7d71\u4e2d\u7f3a\u5c11\u5fc5\u8981\u7684\u5eab\u6216\u5305\u3002<\/p>\n<ul>\n<li><strong>\u66f4\u65b0\u7cfb\u7d71\uff1a<\/strong>\u5728\u5b89\u88dd MySQL \u4e4b\u524d\uff0c\u5efa\u8b70\u5148\u66f4\u65b0\u7cfb\u7d71\u4ee5\u78ba\u4fdd\u6240\u6709\u5305\u90fd\u662f\u6700\u65b0\u7684\uff1a<\/li>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/pre>\n<li><strong>\u5b89\u88dd\u7f3a\u5931\u7684\u4f9d\u8cf4\uff1a<\/strong>\u5982\u679c\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\u51fa\u73fe\u4f9d\u8cf4\u932f\u8aa4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u81ea\u52d5\u4fee\u5fa9\uff1a<\/li>\n<pre><code>sudo apt --fix-broken install<\/code><\/pre>\n<\/ul>\n<h3 id=\"4-mysql-%e8%b3%87%e6%96%99%e6%90%8d%e5%a3%9e-xPswZxSpkC\">4. MySQL \u8cc7\u6599\u640d\u58de<\/h3>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u8cc7\u6599\u5eab\u53ef\u80fd\u6703\u56e0\u70ba\u4e0d\u7576\u95dc\u9589\u6216\u5176\u4ed6\u539f\u56e0\u800c\u640d\u58de\u3002\u9019\u6703\u5c0e\u81f4 MySQL \u7121\u6cd5\u555f\u52d5\u6216\u7121\u6cd5\u8a2a\u554f\u8cc7\u6599\u3002<\/p>\n<ul>\n<li><strong>\u4fee\u5fa9\u8cc7\u6599\u5eab\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5617\u8a66\u4fee\u5fa9\u8cc7\u6599\u5eab\uff1a<\/li>\n<pre><code>mysqlcheck -u root -p --auto-repair --all-databases<\/code><\/pre>\n<li><strong>\u91cd\u65b0\u5b89\u88dd MySQL\uff1a<\/strong>\u5982\u679c\u4fee\u5fa9\u7121\u6548\uff0c\u53ef\u80fd\u9700\u8981\u5b8c\u5168\u5378\u8f09\u4e26\u91cd\u65b0\u5b89\u88dd MySQL\uff1a<\/li>\n<pre><code>sudo apt remove --purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*<br>sudo apt autoremove<br>sudo apt autoclean<br>sudo apt install mysql-server<\/code><\/pre>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-xPswZxSpkC\">\u7e3d\u7d50<\/h2>\n<p>\u5728 Ubuntu \u7cfb\u7d71\u4e0a\u91cd\u65b0\u5b89\u88dd MySQL \u6642\uff0c\u4f7f\u7528\u8005\u53ef\u80fd\u6703\u9047\u5230\u591a\u7a2e\u932f\u8aa4\u3002\u901a\u904e\u6aa2\u67e5\u914d\u7f6e\u6587\u4ef6\u3001\u7528\u6236\u6b0a\u9650\u3001\u4f9d\u8cf4\u554f\u984c\u53ca\u8cc7\u6599\u5eab\u72c0\u614b\uff0c\u901a\u5e38\u53ef\u4ee5\u6709\u6548\u89e3\u6c7a\u9019\u4e9b\u554f\u984c\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\u4f86\u904b\u884c\u60a8\u7684 MySQL \u8cc7\u6599\u5eab\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u6c7a\u5728 Ubuntu \u4e0a\u91cd\u65b0\u5b89\u88dd MySQL \u6642\u9047\u5230\u7684\u5e38\u898b\u932f\u8aa4\uff0c\u63d0\u4f9b\u6b65\u9a5f\u548c\u6280\u5de7\uff0c\u78ba\u4fdd\u9806\u5229\u5b89\u88dd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-52431","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=52431"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52431\/revisions"}],"predecessor-version":[{"id":52432,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52431\/revisions\/52432"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=52431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=52431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=52431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}