{"id":1656,"date":"2025-05-08T15:36:06","date_gmt":"2025-05-08T07:36:06","guid":{"rendered":"https:\/\/minglelu.cn\/?p=1656"},"modified":"2025-07-01T14:44:43","modified_gmt":"2025-07-01T06:44:43","slug":"mysql-rootlocalhost-%e7%94%a8%e6%88%b7%e6%81%a2%e5%a4%8d%e6%9d%83%e9%99%90%e5%92%8c%e5%af%86%e7%a0%81%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/minglelu.cn\/index.php\/2025\/05\/08\/1656\/","title":{"rendered":"MySQL root@localhost \u7528\u6237\u6062\u590d\u6743\u9650\u548c\u5bc6\u7801\u6d41\u7a0b"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">MySQL <code>root<\/code> \u7528\u6237\u6062\u590d\u6743\u9650\u548c\u5bc6\u7801\u6d41\u7a0b<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u80cc\u666f<\/strong><br>\u7248\u672cmysql5.7<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 MySQL \u4f7f\u7528 <strong><code>--skip-grant-tables<\/code><\/strong> \u542f\u52a8\u6a21\u5f0f\u65f6\uff0c\u6743\u9650\u8868\u88ab\u8df3\u8fc7\uff0c\u5bfc\u81f4\u7528\u6237\u65e0\u6cd5\u6267\u884c\u6743\u9650\u76f8\u5173\u64cd\u4f5c\u3002\u4e3a\u4e86\u6062\u590d <code>root<\/code> \u7528\u6237\u7684\u6743\u9650\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u4fee\u590d MySQL \u7528\u6237\u8868\u5e76\u6062\u590d\u6b63\u5e38\u6a21\u5f0f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6b65\u9aa4 1\uff1a\u4f7f\u7528 <code>--skip-grant-tables<\/code> \u542f\u52a8 MySQL<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u505c\u6b62 MySQL \u670d\u52a1\uff1a<\/strong> \u9996\u5148\uff0c\u505c\u6b62 MySQL \u670d\u52a1\u3002\u6b64\u6b65\u9aa4\u53ef\u4ee5\u786e\u4fdd MySQL \u4e0d\u4f1a\u81ea\u52a8\u91cd\u65b0\u542f\u52a8\u5e76\u4e14\u4e0d\u4f1a\u4f7f\u7528\u6388\u6743\u8868\u3002<br><code>pkill -f -- --skip-grant-tables<\/code><\/li>\n\n\n\n<li><strong>\u4ee5\u8df3\u8fc7\u6743\u9650\u8868\u6a21\u5f0f\u542f\u52a8 MySQL\uff1a<\/strong> \u4ee5\u8df3\u8fc7\u6743\u9650\u8868\u6a21\u5f0f\u542f\u52a8 MySQL\uff0c\u5141\u8bb8\u4f60\u5728\u6ca1\u6709\u6743\u9650\u68c0\u67e5\u7684\u60c5\u51b5\u4e0b\u8bbf\u95ee MySQl<br><code>sudo -u mysql \/usr\/sbin\/mysqld --skip-grant-tables --skip-networking &amp;<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6b65\u9aa4 2\uff1a\u66f4\u65b0 <code>root<\/code> \u7528\u6237\u7684\u5bc6\u7801<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64\u6a21\u5f0f\u4e0b\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u66f4\u65b0\u7528\u6237\u7684\u5bc6\u7801\u3002\u9996\u5148\uff0c\u767b\u5f55\u5230 MySQL\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\uff0c\u6267\u884c\u4ee5\u4e0b SQL \u6765\u66f4\u65b0 <code>root<\/code> \u7528\u6237\u7684\u5bc6\u7801\uff08\u6b64\u5904\u4f7f\u7528 <code>root<\/code> \u7528\u6237\u548c <code>localhost<\/code> \u4e3b\u673a\u540d\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>UPDATE mysql.user SET authentication_string = PASSWORD('Ww265325') WHERE user = 'root' AND host = 'localhost';\nFLUSH PRIVILEGES;\n<\/code><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-vivid-red-color has-text-color has-link-color wp-elements-d74d40005917578aa5636dbe2ddc5db9\"><code>authentication_string = PASSWORD('Ww265325')<\/code>\uff1a\u66f4\u65b0 <code>root<\/code> \u7528\u6237\u5bc6\u7801\u4e3a <code>Ww265325<\/code>\u3002<\/li>\n\n\n\n<li><code>FLUSH PRIVILEGES<\/code>\uff1a\u5237\u65b0\u6743\u9650\uff0c\u786e\u4fdd\u4fee\u6539\u751f\u6548\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6b65\u9aa4 3\uff1a\u6062\u590d <code>root<\/code> \u7528\u6237\u7684\u6743\u9650<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u5728\u8df3\u8fc7\u6743\u9650\u6a21\u5f0f\u4e0b\uff0c<code>root<\/code> \u7528\u6237\u7684\u6743\u9650\u672a\u5b8c\u5168\u751f\u6548\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u4fee\u590d\u6743\u9650\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">UPDATE mysql.user SET Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y', Delete_priv = 'Y', <br>    Create_priv = 'Y', Drop_priv = 'Y', Reload_priv = 'Y', Shutdown_priv = 'Y', <br>    Process_priv = 'Y', File_priv = 'Y', Grant_priv = 'Y', References_priv = 'Y', <br>    Index_priv = 'Y', Alter_priv = 'Y', Show_db_priv = 'Y', Super_priv = 'Y', <br>    Create_tmp_table_priv = 'Y', Lock_tables_priv = 'Y', Execute_priv = 'Y', <br>    Repl_slave_priv = 'Y', Repl_client_priv = 'Y', Create_view_priv = 'Y', <br>    Show_view_priv = 'Y', Create_routine_priv = 'Y', Alter_routine_priv = 'Y', <br>    Create_user_priv = 'Y', Event_priv = 'Y', Trigger_priv = 'Y', Create_tablespace_priv = 'Y' <br>WHERE user = 'root' AND host = 'localhost';<br>FLUSH PRIVILEGES;<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8fd9\u6761\u8bed\u53e5\u4e3a <code>root<\/code> \u7528\u6237\u5728 <code>localhost<\/code> \u4e0a\u8d4b\u4e88\u4e86\u6240\u6709\u5e38\u7528\u6743\u9650\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6b65\u9aa4 4\uff1a\u5173\u95ed\u8df3\u8fc7\u6743\u9650\u6a21\u5f0f\u5e76\u91cd\u65b0\u542f\u52a8 MySQL<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u505c\u6b62\u8df3\u8fc7\u6743\u9650\u6a21\u5f0f\uff1a<\/strong> \u505c\u6b62\u5f53\u524d MySQL \u8fdb\u7a0b\uff0c\u6062\u590d\u6b63\u5e38\u7684\u6743\u9650\u8868\uff1a<br><code>pkill -f -- --skip-grant-tables<\/code><\/li>\n\n\n\n<li><strong>\u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1\uff1a<\/strong> \u4f7f\u7528\u7cfb\u7edf\u670d\u52a1\u91cd\u65b0\u542f\u52a8 MySQL\uff1a<br><code>systemctl start mysqld<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6b65\u9aa4 5\uff1a\u9a8c\u8bc1<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\uff0c\u9a8c\u8bc1 <code>root<\/code> \u7528\u6237\u662f\u5426\u5df2\u6062\u590d\u6b63\u5e38\u6743\u9650\u5e76\u80fd\u591f\u767b\u5f55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql -u root -p<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165\u4f60\u5728\u6b65\u9aa4 2 \u4e2d\u8bbe\u7f6e\u7684\u5bc6\u7801 <code>Ww265325<\/code>\uff0c\u5e94\u8be5\u80fd\u591f\u6210\u529f\u767b\u5f55\u5e76\u4e14\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\u547d\u4ee4\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>--skip-grant-tables<\/code> \u542f\u52a8 MySQL\uff0c\u8df3\u8fc7\u6743\u9650\u68c0\u67e5\u3002<\/li>\n\n\n\n<li>\u5728 MySQL \u4e2d\u76f4\u63a5\u66f4\u65b0 <code>root<\/code> \u7528\u6237\u7684\u5bc6\u7801\u3002<\/li>\n\n\n\n<li>\u624b\u52a8\u4fee\u590d <code>root<\/code> \u7528\u6237\u7684\u6743\u9650\uff0c\u786e\u4fdd\u5176\u5177\u6709\u6240\u6709\u5fc5\u8981\u7684\u6743\u9650\u3002<\/li>\n\n\n\n<li>\u5173\u95ed\u8df3\u8fc7\u6743\u9650\u6a21\u5f0f\uff0c\u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1\u3002<\/li>\n\n\n\n<li>\u6d4b\u8bd5 <code>root<\/code> \u7528\u6237\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u767b\u5f55\u5e76\u62e5\u6709\u8db3\u591f\u6743\u9650\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>MySQL root \u7528\u6237\u6062\u590d\u6743\u9650\u548c\u5bc6\u7801\u6d41\u7a0b \u80cc\u666f\u7248\u672cmysql5.7 \u5728 MySQL \u4f7f\u7528 &#8211;skip-grant-tables \u542f\u52a8\u6a21\u5f0f\u65f6\uff0c\u6743\u9650\u8868\u88ab\u8df3\u8fc7\uff0c\u5bfc\u81f4\u7528\u6237\u65e0\u6cd5\u6267\u884c\u6743\u9650\u76f8\u5173\u64cd\u4f5c\u3002\u4e3a\u4e86\u6062\u590d root \u7528\u6237\u7684\u6743\u9650\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u4fee\u590d MySQL \u7528\u6237\u8868\u5e76\u6062\u590d\u6b63\u5e38\u6a21\u5f0f\u3002 \u6b65\u9aa4 1\uff1a\u4f7f\u7528 &#8211;skip-grant-tables \u542f\u52a8 MySQL \u6b65\u9aa4 2\uff1a\u66f4\u65b0 root \u7528\u6237\u7684\u5bc6\u7801 \u5728\u6b64\u6a21\u5f0f\u4e0b\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1657,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,18],"tags":[],"class_list":["post-1656","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-18"],"_links":{"self":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts\/1656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1656"}],"version-history":[{"count":6,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts\/1656\/revisions"}],"predecessor-version":[{"id":1759,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts\/1656\/revisions\/1759"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/media\/1657"}],"wp:attachment":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}