{"id":195813,"date":"2024-11-13T18:07:24","date_gmt":"2024-11-13T10:07:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/195813\/"},"modified":"2024-11-13T18:07:25","modified_gmt":"2024-11-13T10:07:25","slug":"%e5%9c%a8ubuntu%e4%b8%8a%e5%ae%89%e8%a3%9d%e5%92%8c%e9%85%8d%e7%bd%aemysql%e4%bf%9d%e5%a7%86%e7%b4%9a%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/195813\/","title":{"rendered":"\u5728Ubuntu\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u4fdd\u59c6\u7d1a\u6559\u7a0b"},"content":{"rendered":"<h1 id=\"%e5%9c%a8ubuntu%e4%b8%8a%e5%ae%89%e8%a3%9d%e5%92%8c%e9%85%8d%e7%bd%aemysql%e4%bf%9d%e5%a7%86%e7%b4%9a%e6%95%99%e7%a8%8b-oDHHWFXKOB\">\u5728Ubuntu\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u4fdd\u59c6\u7d1a\u6559\u7a0b<\/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\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u4f01\u696d\u61c9\u7528\uff0cMySQL\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6559\u7a0b\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u5728Ubuntu\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\uff0c\u8b93\u60a8\u80fd\u5920\u8f15\u9b06\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-oDHHWFXKOB\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684Ubuntu\u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9dmysql-oDHHWFXKOB\">\u5b89\u88ddMySQL<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u5c07\u5b89\u88ddMySQL\u4f3a\u670d\u5668\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88ddMySQL\uff1a<\/p>\n<pre><code>sudo apt install mysql-server<\/code><\/pre>\n<p>\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u7cfb\u7d71\u6703\u81ea\u52d5\u4e0b\u8f09\u4e26\u5b89\u88ddMySQL\u53ca\u5176\u4f9d\u8cf4\u9805\u3002\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\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\u679cMySQL\u670d\u52d9\u6b63\u5728\u904b\u884c\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230\u201cactive (running)\u201d\u7684\u72c0\u614b\u3002<\/p>\n<h2 id=\"%e5%ae%89%e5%85%a8%e9%85%8d%e7%bd%ae-oDHHWFXKOB\">\u5b89\u5168\u914d\u7f6e<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u5efa\u8b70\u60a8\u904b\u884cMySQL\u7684\u5b89\u5168\u914d\u7f6e\u8173\u672c\uff0c\u4ee5\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5\u5b89\u5168\u914d\u7f6e\u8173\u672c\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u5728\u57f7\u884c\u6b64\u547d\u4ee4\u5f8c\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u9032\u884c\u4e00\u7cfb\u5217\u7684\u5b89\u5168\u8a2d\u7f6e\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u8a2d\u7f6eroot\u7528\u6236\u7684\u5bc6\u78bc<\/li>\n<li>\u522a\u9664\u533f\u540d\u7528\u6236<\/li>\n<li>\u7981\u6b62root\u9060\u7a0b\u767b\u9304<\/li>\n<li>\u522a\u9664\u6e2c\u8a66\u6578\u64da\u5eab<\/li>\n<li>\u91cd\u65b0\u52a0\u8f09\u6b0a\u9650\u8868<\/li>\n<\/ul>\n<p>\u6839\u64da\u63d0\u793a\u9032\u884c\u76f8\u61c9\u7684\u9078\u64c7\uff0c\u9019\u5c07\u6709\u52a9\u65bc\u52a0\u5f37\u60a8\u7684MySQL\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e7%99%bb%e9%8c%84mysql-oDHHWFXKOB\">\u767b\u9304MySQL<\/h2>\n<p>\u5b8c\u6210\u5b89\u5168\u914d\u7f6e\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304\u5230MySQL\uff1a<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u8f38\u5165\u4e4b\u524d\u8a2d\u7f6e\u7684root\u5bc6\u78bc\u3002\u6210\u529f\u767b\u9304\u5f8c\uff0c\u60a8\u5c07\u770b\u5230MySQL\u63d0\u793a\u7b26\uff0c\u9019\u610f\u5473\u8457\u60a8\u5df2\u7d93\u53ef\u4ee5\u958b\u59cb\u4f7f\u7528MySQL\u4e86\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-oDHHWFXKOB\">\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u4f86\u7ba1\u7406\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<pre><code>CREATE DATABASE my_database;\nCREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';\nFLUSH PRIVILEGES;<\/code><\/pre>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c07\u5275\u5efa\u4e00\u500b\u540d\u70ba\u201cmy_database\u201d\u7684\u6578\u64da\u5eab\uff0c\u4e26\u5275\u5efa\u4e00\u500b\u540d\u70ba\u201cmy_user\u201d\u7684\u7528\u6236\uff0c\u8a72\u7528\u6236\u64c1\u6709\u5c0d\u8a72\u6578\u64da\u5eab\u7684\u6240\u6709\u6b0a\u9650\u3002<\/p>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e9%80%a3%e6%8e%a5-oDHHWFXKOB\">\u6e2c\u8a66\u9023\u63a5<\/h2>\n<p>\u70ba\u4e86\u78ba\u4fdd\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u65b0\u5275\u5efa\u7684\u7528\u6236\u767b\u9304\u5230MySQL\uff1a<\/p>\n<pre><code>mysql -u my_user -p<\/code><\/pre>\n<p>\u8f38\u5165\u5bc6\u78bc\u5f8c\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u6210\u529f\u767b\u9304\u4e26\u8a2a\u554f\u201cmy_database\u201d\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-oDHHWFXKOB\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728Ubuntu\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\uff0c\u5305\u62ec\u5b89\u5168\u8a2d\u7f6e\u3001\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u5275\u5efa\u7b49\u6b65\u9a5f\u3002\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u5c07\u5e6b\u52a9\u60a8\u958b\u59cb\u4f7f\u7528MySQL\u9032\u884c\u6578\u64da\u7ba1\u7406\u3002\u5982\u679c\u60a8\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\u90e8\u7f72\u60a8\u7684MySQL\u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728Ubuntu\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u7684\u8a73\u7d30\u6b65\u9a5f\uff0c\u9069\u5408\u521d\u5b78\u8005\u7684\u4fdd\u59c6\u7d1a\u6559\u7a0b\uff0c\u8f15\u9b06\u4e0a\u624b\u6578\u64da\u5eab\u7ba1\u7406\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-195813","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195813","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=195813"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195813\/revisions"}],"predecessor-version":[{"id":195814,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195813\/revisions\/195814"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=195813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=195813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=195813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}