{"id":170205,"date":"2024-11-06T22:01:20","date_gmt":"2024-11-06T14:01:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/170205\/"},"modified":"2024-11-06T22:01:20","modified_gmt":"2024-11-06T14:01:20","slug":"%e9%85%8d%e7%bd%aemysql%e8%88%87%e5%8d%b8%e8%bc%89mysql%e5%af%a6%e6%93%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/170205\/","title":{"rendered":"\u914d\u7f6eMySQL\u8207\u5378\u8f09MySQL\u5be6\u64cd"},"content":{"rendered":"<h1 id=\"%e9%85%8d%e7%bd%aemysql%e8%88%87%e5%8d%b8%e8%bc%89mysql%e5%af%a6%e6%93%8d-ChHmWsECKb\">\u914d\u7f6eMySQL\u8207\u5378\u8f09MySQL\u5be6\u64cd<\/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\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u4f01\u696d\uff0cMySQL\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u4f3a\u670d\u5668\u4e0a\u914d\u7f6eMySQL\u4ee5\u53ca\u5982\u4f55\u5378\u8f09MySQL\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u7ba1\u7406\u5176\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e9%85%8d%e7%bd%aemysql-ChHmWsECKb\">\u4e00\u3001\u914d\u7f6eMySQL<\/h2>\n<h3 id=\"1-%e5%ae%89%e8%a3%9dmysql-ChHmWsECKb\">1. \u5b89\u88ddMySQL<\/h3>\n<p>\u5728Linux\u7cfb\u7d71\u4e0a\u5b89\u88ddMySQL\u975e\u5e38\u7c21\u55ae\u3002\u4ee5Ubuntu\u70ba\u4f8b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install mysql-server<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5MySQL\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start mysql<\/code><\/pre>\n<h3 id=\"2-%e5%ae%89%e5%85%a8%e9%85%8d%e7%bd%ae-ChHmWsECKb\">2. \u5b89\u5168\u914d\u7f6e<\/h3>\n<p>\u5b89\u88ddMySQL\u5f8c\uff0c\u5efa\u8b70\u904b\u884c\u5b89\u5168\u914d\u7f6e\u8173\u672c\u4ee5\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u9019\u500b\u8173\u672c\u6703\u5f15\u5c0e\u60a8\u8a2d\u7f6eroot\u5bc6\u78bc\u3001\u522a\u9664\u533f\u540d\u7528\u6236\u3001\u7981\u6b62root\u9060\u7a0b\u767b\u9304\u4ee5\u53ca\u522a\u9664\u6e2c\u8a66\u6578\u64da\u5eab\u7b49\u9078\u9805\u3002\u6839\u64da\u63d0\u793a\u9032\u884c\u64cd\u4f5c\u5373\u53ef\u3002<\/p>\n<h3 id=\"3-%e7%99%bb%e9%8c%84mysql-ChHmWsECKb\">3. \u767b\u9304MySQL<\/h3>\n<p>\u5b8c\u6210\u5b89\u5168\u914d\u7f6e\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304MySQL\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u8f38\u5165\u5bc6\u78bc\uff0c\u8f38\u5165\u5f8c\u5373\u53ef\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<h3 id=\"4-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-ChHmWsECKb\">4. \u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h3>\n<p>\u5728MySQL\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u4ee5\u4fbf\u65bc\u7ba1\u7406\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u793a\u4f8b\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';<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u60a8\u5c31\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70bamy_database\u7684\u6578\u64da\u5eab\u548c\u4e00\u500b\u540d\u70bamy_user\u7684\u7528\u6236\uff0c\u4e26\u6388\u4e88\u8a72\u7528\u6236\u5c0d\u8a72\u6578\u64da\u5eab\u7684\u6240\u6709\u6b0a\u9650\u3002<\/p>\n<h2 id=\"%e4%ba%8c%e3%80%81%e5%8d%b8%e8%bc%89mysql-ChHmWsECKb\">\u4e8c\u3001\u5378\u8f09MySQL<\/h2>\n<h3 id=\"1-%e5%81%9c%e6%ad%a2mysql%e6%9c%8d%e5%8b%99-ChHmWsECKb\">1. \u505c\u6b62MySQL\u670d\u52d9<\/h3>\n<p>\u5728\u5378\u8f09MySQL\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u505c\u6b62MySQL\u670d\u52d9\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl stop mysql<\/code><\/pre>\n<h3 id=\"2-%e5%8d%b8%e8%bc%89mysql-ChHmWsECKb\">2. \u5378\u8f09MySQL<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5378\u8f09MySQL\u53ca\u5176\u76f8\u95dc\u5305\uff1a<\/p>\n<pre><code>sudo apt remove --purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u6703\u522a\u9664MySQL\u7684\u6240\u6709\u6838\u5fc3\u7d44\u4ef6\u3002<\/p>\n<h3 id=\"3-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a%e5%92%8c%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-ChHmWsECKb\">3. \u522a\u9664\u6578\u64da\u548c\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u5982\u679c\u60a8\u5e0c\u671b\u5b8c\u5168\u522a\u9664MySQL\u7684\u6578\u64da\u548c\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo rm -rf \/etc\/mysql \/var\/lib\/mysql<\/code><\/pre>\n<p>\u8acb\u6ce8\u610f\uff0c\u9019\u5c07\u6c38\u4e45\u522a\u9664\u6240\u6709\u6578\u64da\uff0c\u8acb\u52d9\u5fc5\u63d0\u524d\u5099\u4efd\u91cd\u8981\u6578\u64da\u3002<\/p>\n<h3 id=\"4-%e6%b8%85%e7%90%86%e4%b8%8d%e5%86%8d%e9%9c%80%e8%a6%81%e7%9a%84%e4%be%9d%e8%b3%b4%e5%8c%85-ChHmWsECKb\">4. \u6e05\u7406\u4e0d\u518d\u9700\u8981\u7684\u4f9d\u8cf4\u5305<\/h3>\n<p>\u6700\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6e05\u7406\u4e0d\u518d\u9700\u8981\u7684\u4f9d\u8cf4\u5305\uff1a<\/p>\n<pre><code>sudo apt autoremove<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ChHmWsECKb\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728\u4f3a\u670d\u5668\u4e0a\u914d\u7f6e\u548c\u5378\u8f09MySQL\u3002\u901a\u904e\u7c21\u55ae\u7684\u547d\u4ee4\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u5b89\u88dd\u3001\u914d\u7f6e\u548c\u7ba1\u7406MySQL\u6578\u64da\u5eab\u3002\u7121\u8ad6\u60a8\u662f\u958b\u767c\u8005\u9084\u662f\u7cfb\u7d71\u7ba1\u7406\u54e1\uff0c\u638c\u63e1\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\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\u6258\u7ba1\u60a8\u7684MySQL\u6578\u64da\u5eab\uff0c\u4eab\u53d7\u66f4\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u66f4\u9ad8\u7684\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u914d\u7f6e\u548c\u5378\u8f09MySQL\uff0c\u638c\u63e1\u5be6\u64cd\u6280\u5de7\uff0c\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\u74b0\u5883\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\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-170205","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170205","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=170205"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170205\/revisions"}],"predecessor-version":[{"id":170206,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170205\/revisions\/170206"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=170205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=170205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=170205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}