{"id":6359,"date":"2024-11-14T09:39:04","date_gmt":"2024-11-14T01:39:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6359\/"},"modified":"2024-11-14T09:39:04","modified_gmt":"2024-11-14T01:39:04","slug":"mysql%e5%bf%98%e8%ae%b0%e5%af%86%e7%a0%81%e6%80%8e%e4%b9%88%e6%9b%b4%e6%94%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6359\/","title":{"rendered":"mysql\u5fd8\u8bb0\u5bc6\u7801\u600e\u4e48\u66f4\u6539"},"content":{"rendered":"<blockquote><p>\n  \u60a8\u53ef\u4ee5\u5148\u505c\u6b62 mysql \u670d\u52a1\uff0c\u518d\u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8\u5b83\uff0c\u91cd\u7f6e\u5bc6\u7801\uff0c\u6388\u4e88\u6743\u9650\uff0c\u5237\u65b0\u6743\u9650\u8868\uff0c\u91cd\u65b0\u542f\u52a8 mysql \u670d\u52a1\uff0c\u6700\u540e\u4f7f\u7528\u65b0\u5bc6\u7801\u767b\u5f55\uff0c\u5373\u53ef\u66f4\u6539\u5fd8\u8bb0\u7684 mysql \u5bc6\u7801\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080102544240741.jpg\" class=\"aligncenter\" title=\"mysql\u5fd8\u8bb0\u5bc6\u7801\u600e\u4e48\u66f4\u6539\u63d2\u56fe\" alt=\"mysql\u5fd8\u8bb0\u5bc6\u7801\u600e\u4e48\u66f4\u6539\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u66f4\u6539\u5fd8\u8bb0\u7684 MySQL \u5bc6\u7801<\/strong><\/p>\n<p>\u5fd8\u8bb0 MySQL \u5bc6\u7801\u53ef\u80fd\u4f1a\u8ba9\u4eba\u611f\u5230\u6cae\u4e27\uff0c\u4f46\u8fd9\u4e0d\u662f\u6ca1\u6709\u89e3\u51b3\u529e\u6cd5\u7684\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u66f4\u6539\u5fd8\u8bb0\u7684 MySQL \u5bc6\u7801\uff1a<\/p>\n<p><strong>1. \u505c\u6b62 MySQL \u670d\u52a1<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u505c\u6b62\u6b63\u5728\u8fd0\u884c\u7684 MySQL \u670d\u52a1\u3002\u5728 Windows \u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u9762\u677f\u4e2d\u7684\u670d\u52a1\u5de5\u5177\u6765\u5b8c\u6210\u3002\u5728 Linux \u548c macOS \u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>sudo service mysql stop<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8 MySQL<\/strong><\/p>\n<p>\u7136\u540e\uff0c\u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8 MySQL\u3002\u8fd9\u5c06\u5141\u8bb8\u60a8\u5728\u4e0d\u4f7f\u7528\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\u8bbf\u95ee\u670d\u52a1\u5668\u3002\u5728 Windows \u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 d.exe \u547d\u4ee4\uff1a<\/p>\n<pre>mysqld --skip-grant-tables<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 Linux \u548c macOS \u4e0a\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>sudo mysqld_safe --skip-grant-tables &amp;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u91cd\u7f6e\u5bc6\u7801<\/strong><\/p>\n<p>\u8fde\u63a5\u5230 MySQL \u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\u6765\u91cd\u7f6e\u5bc6\u7801\uff1a<\/p>\n<pre>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d &#8220;new_password&#8221; \u662f\u60a8\u8981\u8bbe\u7f6e\u7684\u65b0\u5bc6\u7801\u3002<\/p>\n<p><strong>4. \u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p>\u5982\u679croot\u7528\u6237\u6ca1\u6709\u9002\u5f53\u7684\u6743\u9650\uff0c\u8fd8\u9700\u8981\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u5237\u65b0\u6743\u9650\u8868<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u5237\u65b0\u6743\u9650\u8868\u4ee5\u5e94\u7528\u66f4\u6539\uff1a<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1<\/strong><\/p>\n<p>\u5b8c\u6210\u540e\uff0c\u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1\uff1a<\/p>\n<pre>sudo service mysql start<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>7. \u4f7f\u7528\u65b0\u5bc6\u7801\u767b\u5f55<\/strong><\/p>\n<p>\u73b0\u5728\u60a8\u53ef\u4ee5\u4f7f\u7528\u65b0\u5bc6\u7801\u767b\u5f55 MySQL \u4e86\uff1a<\/p>\n<pre>mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u5165\u65b0\u5bc6\u7801\uff0c\u5373\u53ef\u8bbf\u95ee\u6570\u636e\u5e93\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fd8\u8bb0\u5bc6\u7801\u600e\u4e48\u66f4\u6539\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u60a8\u53ef\u4ee5\u5148\u505c\u6b62 mysql \u670d\u52a1\uff0c\u518d\u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8\u5b83\uff0c\u91cd\u7f6e\u5bc6\u7801\uff0c\u6388\u4e88\u6743\u9650\uff0c\u5237\u65b0\u6743\u9650\u8868\uff0c\u91cd\u65b0\u542f\u52a8 mysql \u670d\u52a1\uff0c\u6700\u540e\u4f7f\u7528\u65b0\u5bc6\u7801\u767b\u5f55\uff0c\u5373\u53ef\u66f4\u6539\u5fd8\u8bb0\u7684 mysql \u5bc6\u7801\u3002 \u5982\u4f55\u66f4\u6539\u5fd8\u8bb0\u7684 MySQL \u5bc6\u7801 \u5fd8\u8bb0 MySQL \u5bc6\u7801\u53ef\u80fd\u4f1a\u8ba9\u4eba\u611f\u5230\u6cae\u4e27\uff0c\u4f46\u8fd9\u4e0d\u662f\u6ca1\u6709\u89e3\u51b3\u529e\u6cd5\u7684\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u66f4\u6539\u5fd8\u8bb0\u7684 MySQL \u5bc6\u7801\uff1a 1. \u505c\u6b62 MySQL \u670d\u52a1 \u9996\u5148\uff0c\u505c\u6b62\u6b63\u5728\u8fd0\u884c\u7684 MySQL \u670d\u52a1\u3002\u5728 Windows \u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u9762\u677f\u4e2d\u7684\u670d\u52a1\u5de5\u5177\u6765\u5b8c\u6210\u3002\u5728 Linux \u548c macOS \u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a sudo service mysql stop \u767b\u5f55\u540e\u590d\u5236 2. \u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8 MySQL \u7136\u540e\uff0c\u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8 MySQL\u3002\u8fd9\u5c06\u5141\u8bb8\u60a8\u5728\u4e0d\u4f7f\u7528\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\u8bbf\u95ee\u670d\u52a1\u5668\u3002\u5728 Windows \u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 d.exe \u547d\u4ee4\uff1a mysqld &#8211;skip-grant-tables \u767b\u5f55\u540e\u590d\u5236 \u5728 Linux \u548c macOS \u4e0a\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a sudo mysqld_safe &#8211;skip-grant-tables &amp; \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6359","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6359"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6359\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}