{"id":76392,"date":"2024-10-16T06:17:13","date_gmt":"2024-10-15T22:17:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76392\/"},"modified":"2024-10-16T06:17:13","modified_gmt":"2024-10-15T22:17:13","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%ae%89%e8%a3%9d%e5%9c%a8ubuntu%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%b5%b1%e4%b8%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76392\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u5b89\u88dd\u5728Ubuntu\u64cd\u4f5c\u7cfb\u7d71\u4e0b"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%ae%89%e8%a3%9d%e5%9c%a8ubuntu%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%b5%b1%e4%b8%8b-cvyIkmHOMi\">MySQL\u6578\u64da\u5eab\u5b89\u88dd\u5728Ubuntu\u64cd\u4f5c\u7cfb\u7d71\u4e0b<\/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\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728Ubuntu\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u5b89\u88ddMySQL\u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u6b65\u9a5f\u548c\u6ce8\u610f\u4e8b\u9805\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-cvyIkmHOMi\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684Ubuntu\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\nsudo apt upgrade<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6240\u6709\u7684\u5305\u90fd\u662f\u6700\u65b0\u7684\uff0c\u907f\u514d\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\u51fa\u73fe\u4e0d\u5fc5\u8981\u7684\u554f\u984c\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9dmysql-cvyIkmHOMi\">\u5b89\u88ddMySQL<\/h2>\n<p>\u5728Ubuntu\u4e0a\u5b89\u88ddMySQL\u975e\u5e38\u7c21\u55ae\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528apt\u5305\u7ba1\u7406\u5668\u4f86\u9032\u884c\u5b89\u88dd\u3002\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo apt install mysql-server<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u6703\u81ea\u52d5\u4e0b\u8f09\u4e26\u5b89\u88ddMySQL\u670d\u52d9\u5668\u53ca\u5176\u4f9d\u8cf4\u9805\u3002\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u7cfb\u7d71\u53ef\u80fd\u6703\u8981\u6c42\u4f60\u78ba\u8a8d\u5b89\u88dd\uff0c\u8acb\u6839\u64da\u63d0\u793a\u9032\u884c\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e9%85%8d%e7%bd%aemysql-cvyIkmHOMi\">\u914d\u7f6eMySQL<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0cMySQL\u670d\u52d9\u5668\u6703\u81ea\u52d5\u555f\u52d5\u3002\u4f60\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\u6b63\u5728\u904b\u884c\uff0c\u4f60\u6703\u770b\u5230\u985e\u4f3c\u65bc\u201cactive (running)\u201d\u7684\u72c0\u614b\u3002\u5982\u679c\u670d\u52d9\u672a\u555f\u52d5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5\u5b83\uff1a<\/p>\n<pre><code>sudo systemctl start mysql<\/code><\/pre>\n<h3 id=\"%e5%ae%89%e5%85%a8%e9%85%8d%e7%bd%ae-cvyIkmHOMi\">\u5b89\u5168\u914d\u7f6e<\/h3>\n<p>\u70ba\u4e86\u63d0\u9ad8MySQL\u7684\u5b89\u5168\u6027\uff0c\u5efa\u8b70\u904b\u884c\u5b89\u5168\u914d\u7f6e\u8173\u672c\u3002\u9019\u500b\u8173\u672c\u6703\u5e6b\u52a9\u4f60\u8a2d\u7f6e\u6839\u7528\u6236\u7684\u5bc6\u78bc\u3001\u522a\u9664\u533f\u540d\u7528\u6236\u3001\u7981\u6b62\u9060\u7a0b\u767b\u9304\u7b49\u3002\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u6839\u64da\u63d0\u793a\u9032\u884c\u64cd\u4f5c\uff0c\u9019\u5c07\u6709\u52a9\u65bc\u52a0\u5f37\u4f60\u7684MySQL\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e7%99%bb%e9%8c%84mysql-cvyIkmHOMi\">\u767b\u9304MySQL<\/h2>\n<p>\u5b8c\u6210\u5b89\u5168\u914d\u7f6e\u5f8c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304MySQL\uff1a<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>\u7cfb\u7d71\u6703\u63d0\u793a\u4f60\u8f38\u5165\u6839\u7528\u6236\u7684\u5bc6\u78bc\u3002\u8f38\u5165\u6b63\u78ba\u7684\u5bc6\u78bc\u5f8c\uff0c\u4f60\u5c07\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-cvyIkmHOMi\">\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u5eab\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>CREATE DATABASE my_database;<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5275\u5efa\u4e00\u500b\u7528\u6236\u4e26\u6388\u4e88\u5176\u5c0d\u8a72\u6578\u64da\u5eab\u7684\u8a2a\u554f\u6b0a\u9650\uff1a<\/p>\n<pre><code>CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';<\/code><\/pre>\n<p>\u6700\u5f8c\uff0c\u8a18\u5f97\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>FLUSH PRIVILEGES;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-cvyIkmHOMi\">\u7e3d\u7d50<\/h2>\n<p>\u5728Ubuntu\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u5b89\u88ddMySQL\u6578\u64da\u5eab\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u4f60\u53ef\u4ee5\u8f15\u9b06\u5730\u8a2d\u7f6e\u548c\u914d\u7f6eMySQL\u3002\u7121\u8ad6\u662f\u7528\u65bc\u958b\u767c\u9084\u662f\u751f\u7522\u74b0\u5883\uff0cMySQL\u90fd\u662f\u4e00\u500b\u5f37\u5927\u7684\u6578\u64da\u5eab\u9078\u64c7\u3002\u5982\u679c\u4f60\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u904b\u884c\u4f60\u7684MySQL\u670d\u52d9\uff0c\u9019\u6a23\u53ef\u4ee5\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728Ubuntu\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u5b89\u88ddMySQL\u6578\u64da\u5eab\uff0c\u7c21\u55ae\u6b65\u9a5f\u52a9\u4f60\u5feb\u901f\u642d\u5efa\u6578\u64da\u7ba1\u7406\u74b0\u5883\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-76392","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76392","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=76392"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76392\/revisions"}],"predecessor-version":[{"id":76393,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76392\/revisions\/76393"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}