{"id":194533,"date":"2024-11-13T07:27:19","date_gmt":"2024-11-12T23:27:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/194533\/"},"modified":"2024-11-13T07:27:21","modified_gmt":"2024-11-12T23:27:21","slug":"%e7%94%a8linux%e5%ae%89%e8%a3%9dmysql%e6%99%82%e7%94%a2%e7%94%9f%e5%95%8f%e9%a1%8c%e7%a0%b4%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/194533\/","title":{"rendered":"\u7528linux\u5b89\u88ddMySQL\u6642\u7522\u751f\u554f\u984c\u7834\u89e3"},"content":{"rendered":"<h1 id=\"%e7%94%a8linux%e5%ae%89%e8%a3%9dmysql%e6%99%82%e7%94%a2%e7%94%9f%e5%95%8f%e9%a1%8c%e7%a0%b4%e8%a7%a3-IQcDpZYCox\">\u7528Linux\u5b89\u88ddMySQL\u6642\u7522\u751f\u554f\u984c\u7834\u89e3<\/h1>\n<p>MySQL\u662f\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u96d6\u7136\u5728Linux\u4e0a\u5b89\u88ddMySQL\u901a\u5e38\u662f\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u4f46\u6709\u6642\u5019\u7528\u6236\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u554f\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5728Linux\u7cfb\u7d71\u4e0a\u5b89\u88ddMySQL\u6642\u53ef\u80fd\u51fa\u73fe\u7684\u5e38\u898b\u554f\u984c\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d%e5%89%8d%e7%9a%84%e6%ba%96%e5%82%99-IQcDpZYCox\">\u5b89\u88dd\u524d\u7684\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88ddMySQL\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684Linux\u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u78ba\u4fdd\u4f60\u7684\u7cfb\u7d71\u4e0a\u5df2\u7d93\u5b89\u88dd\u4e86\u5fc5\u8981\u7684\u4f9d\u8cf4\u5305\u3002\u5c0d\u65bc\u5927\u591a\u6578Linux\u767c\u884c\u7248\uff0c\u9019\u4e9b\u4f9d\u8cf4\u5305\u901a\u5e38\u6703\u5728\u5b89\u88ddMySQL\u6642\u81ea\u52d5\u5b89\u88dd\uff0c\u4f46\u6709\u6642\u5019\u624b\u52d5\u5b89\u88dd\u4e5f\u662f\u5fc5\u8981\u7684\u3002<\/p>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e5%ae%89%e8%a3%9d%e5%95%8f%e9%a1%8c%e5%8f%8a%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-IQcDpZYCox\">\u5e38\u898b\u5b89\u88dd\u554f\u984c\u53ca\u89e3\u6c7a\u65b9\u6848<\/h2>\n<h3 id=\"1-%e7%84%a1%e6%b3%95%e6%89%be%e5%88%b0mysql%e5%8c%85-IQcDpZYCox\">1. \u7121\u6cd5\u627e\u5230MySQL\u5305<\/h3>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528\u5305\u7ba1\u7406\u5668\uff08\u5982apt\u6216yum\uff09\u6642\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u201c\u7121\u6cd5\u627e\u5230MySQL\u5305\u201d\u7684\u932f\u8aa4\u3002\u9019\u901a\u5e38\u662f\u56e0\u70ba\u4f60\u7684\u7cfb\u7d71\u672a\u6b63\u78ba\u914d\u7f6eMySQL\u7684\u5b98\u65b9\u5b58\u5132\u5eab\u3002\u8981\u89e3\u6c7a\u6b64\u554f\u984c\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u5c0d\u65bcDebian\/Ubuntu\u7cfb\u7d71\uff0c\u9996\u5148\u6dfb\u52a0MySQL\u7684\u5b98\u65b9\u5b58\u5132\u5eab\uff1a<\/li>\n<pre><code>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5072E1F5<\/code><\/pre>\n<pre><code>echo \"deb http:\/\/repo.mysql.com\/apt\/ubuntu\/ $(lsb_release -cs) mysql-8.0\" | sudo tee \/etc\/apt\/sources.list.d\/mysql.list<\/code><\/pre>\n<li>\u7136\u5f8c\u66f4\u65b0\u5305\u5217\u8868\u4e26\u5b89\u88ddMySQL\uff1a<\/li>\n<pre><code>sudo apt update<\/code><\/pre>\n<pre><code>sudo apt install mysql-server<\/code><\/pre>\n<\/ul>\n<h3 id=\"2-%e5%ae%89%e8%a3%9d%e9%81%8e%e7%a8%8b%e4%b8%ad%e5%87%ba%e7%8f%be%e9%8c%af%e8%aa%a4-IQcDpZYCox\">2. \u5b89\u88dd\u904e\u7a0b\u4e2d\u51fa\u73fe\u932f\u8aa4<\/h3>\n<p>\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u6703\u9047\u5230\u5404\u7a2e\u932f\u8aa4\u4fe1\u606f\uff0c\u4f8b\u5982\u201c\u4f9d\u8cf4\u6027\u554f\u984c\u201d\u6216\u201c\u5b89\u88dd\u5931\u6557\u201d\u3002\u9019\u4e9b\u554f\u984c\u901a\u5e38\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u65b9\u5f0f\u89e3\u6c7a\uff1a<\/p>\n<ul>\n<li>\u6aa2\u67e5\u4e26\u4fee\u5fa9\u4f9d\u8cf4\u6027\u554f\u984c\uff1a<\/li>\n<pre><code>sudo apt --fix-broken install<\/code><\/pre>\n<li>\u6e05\u7406\u672a\u5b8c\u6210\u7684\u5b89\u88dd\uff1a<\/li>\n<pre><code>sudo dpkg --configure -a<\/code><\/pre>\n<\/ul>\n<h3 id=\"3-mysql%e6%9c%8d%e5%8b%99%e7%84%a1%e6%b3%95%e5%95%9f%e5%8b%95-IQcDpZYCox\">3. MySQL\u670d\u52d9\u7121\u6cd5\u555f\u52d5<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0cMySQL\u670d\u52d9\u53ef\u80fd\u7121\u6cd5\u555f\u52d5\u3002\u9019\u53ef\u80fd\u662f\u7531\u65bc\u914d\u7f6e\u6587\u4ef6\u932f\u8aa4\u6216\u7aef\u53e3\u885d\u7a81\u5f15\u8d77\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5MySQL\u670d\u52d9\u7684\u72c0\u614b\uff1a<\/p>\n<pre><code>sudo systemctl status mysql<\/code><\/pre>\n<p>\u5982\u679c\u670d\u52d9\u672a\u555f\u52d5\uff0c\u53ef\u4ee5\u67e5\u770b\u65e5\u8a8c\u6587\u4ef6\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\uff1a<\/p>\n<pre><code>sudo journalctl -xe<\/code><\/pre>\n<p>\u6839\u64da\u65e5\u8a8c\u4e2d\u7684\u932f\u8aa4\u4fe1\u606f\u9032\u884c\u76f8\u61c9\u7684\u8abf\u6574\uff0c\u4e26\u5617\u8a66\u91cd\u65b0\u555f\u52d5MySQL\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start mysql<\/code><\/pre>\n<h3 id=\"4-%e5%bf%98%e8%a8%98mysql-root%e5%af%86%e7%a2%bc-IQcDpZYCox\">4. \u5fd8\u8a18MySQL root\u5bc6\u78bc<\/h3>\n<p>\u5982\u679c\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\u5fd8\u8a18\u4e86MySQL\u7684root\u5bc6\u78bc\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6b65\u9a5f\u91cd\u7f6e\u5bc6\u78bc\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\u505c\u6b62MySQL\u670d\u52d9\uff1a<\/li>\n<pre><code>sudo systemctl stop mysql<\/code><\/pre>\n<li>\u7136\u5f8c\u4ee5\u5b89\u5168\u6a21\u5f0f\u555f\u52d5MySQL\uff1a<\/li>\n<pre><code>sudo mysqld_safe --skip-grant-tables &amp;<\/code><\/pre>\n<li>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528MySQL\u5ba2\u6236\u7aef\u9023\u63a5\u5230\u6578\u64da\u5eab\uff1a<\/li>\n<pre><code>mysql -u root<\/code><\/pre>\n<li>\u5728MySQL\u63d0\u793a\u7b26\u4e0b\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u91cd\u7f6e\u5bc6\u78bc\uff1a<\/li>\n<pre><code>FLUSH PRIVILEGES; SET PASSWORD FOR 'root'@'localhost' = PASSWORD('\u65b0\u5bc6\u78bc');<\/code><\/pre>\n<li>\u6700\u5f8c\uff0c\u91cd\u555fMySQL\u670d\u52d9\uff1a<\/li>\n<pre><code>sudo systemctl restart mysql<\/code><\/pre>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-IQcDpZYCox\">\u7e3d\u7d50<\/h2>\n<p>\u5728Linux\u4e0a\u5b89\u88ddMySQL\u6642\uff0c\u96d6\u7136\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u554f\u984c\uff0c\u4f46\u5927\u591a\u6578\u60c5\u6cc1\u4e0b\u90fd\u53ef\u4ee5\u901a\u904e\u4e0a\u8ff0\u65b9\u6cd5\u8f15\u9b06\u89e3\u6c7a\u3002\u7121\u8ad6\u662f\u4f9d\u8cf4\u6027\u554f\u984c\u3001\u670d\u52d9\u555f\u52d5\u5931\u6557\u9084\u662f\u5bc6\u78bc\u91cd\u7f6e\uff0c\u4e86\u89e3\u9019\u4e9b\u5e38\u898b\u554f\u984c\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u5b89\u88dd\u6548\u7387\u3002\u5982\u679c\u4f60\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u904b\u884c\u4f60\u7684MySQL\u6578\u64da\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>\u63a2\u7d22\u5728Linux\u4e0a\u5b89\u88ddMySQL\u6642\u5e38\u898b\u554f\u984c\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\uff0c\u52a9\u60a8\u9806\u5229\u5b8c\u6210\u5b89\u88dd\u904e\u7a0b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-194533","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/194533","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=194533"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/194533\/revisions"}],"predecessor-version":[{"id":194534,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/194533\/revisions\/194534"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=194533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=194533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=194533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}