{"id":797,"date":"2011-03-05T22:28:32","date_gmt":"2011-03-05T14:28:32","guid":{"rendered":"http:\/\/www.jpuyy.com\/blog\/?p=797"},"modified":"2013-01-28T17:02:43","modified_gmt":"2013-01-28T09:02:43","slug":"mysql-reset-root-password","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=797","title":{"rendered":"Mysql\u5fd8\u8bb0\u5bc6\u7801\u65f6\u91cd\u7f6e\u5bc6\u7801"},"content":{"rendered":"<p>\u65b9\u6cd5\u4e00\uff1a<\/p>\n<p>\u4e00\u4e2a\u4e2d\u5fc3:\u505c\u6b62\u670d\u52a1,\u8f7d\u5165\u5b89\u5168\u6a21\u5f0f<\/p>\n<pre>killall -TERM mysqld<\/pre>\n<p>\u7136\u540e<\/p>\n<pre>mysqld --skip-grant-tables &amp;<\/pre>\n<p>\u4e24\u4e2a\u57fa\u672c\u70b9\uff1a\u66f4\u65b0user\u8868\uff0c\u5237\u65b0\u6743\u9650<\/p>\n<pre>use mysql;\r\n update user set password=password(\"newpass\") where user=\"root\";\r\n flush privileges;<\/pre>\n<p>\u5982\u679c\u4e0d\u65b9\u4fbf\u7528mysql\u7684cli\u754c\u9762\u4ea4\u4e92<br \/>\n\u8c03\u7528mysqladmin\u5373\u53ef<\/p>\n<pre>mysqladmin -u root flush-privileges password \"newpassword\"<\/pre>\n<p>&nbsp;<\/p>\n<p>\u65b9\u6cd5\u4e8c\uff08debian\u4eb2\u6d4b\uff09\uff1a<\/p>\n<p>\u76f4\u63a5\u4f7f\u7528\/etc\/mysql\/debian.cnf\u6587\u4ef6\u4e2d[client]\u8282\u63d0\u4f9b\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801 \u5907\u7528<\/p>\n<p>mysql -u debian-sys-maint -p<br \/>\nEnter password: &lt;\u8f93\u5165[client]\u8282\u7684\u5bc6\u7801&gt;<\/p>\n<p>mysql&gt; show databases;<\/p>\n<p>mysql&gt; use mysql;<\/p>\n<p>mysql&gt; show tables;<\/p>\n<p>\u8fd9\u4e2a\u65f6\u5019\u4f7f\u7528user\u8868<\/p>\n<p>mysql&gt; UPDATE user SET Password=PASSWORD(&#8216;newpassword&#8217;) where USER=&#8217;root&#8217;;<\/p>\n<p>Query OK, 3 rows affected (0.00 sec)<br \/>\nRows matched: 3\u00a0 Changed: 3\u00a0 Warnings: 0<br \/>\nmysql&gt; FLUSH PRIVILEGES;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<br \/>\nmysql&gt; quit<\/p>\n<p># mysql -u root -p<br \/>\nEnter password: &lt;\u8f93\u5165\u65b0\u8bbe\u7684\u5bc6\u7801newpassword&gt;<br \/>\nmysql&gt;<\/p>\n<p>\u65b9\u6cd5\u4e09(centos 6.2\u4eb2\u6d4b\uff0c\u7b49\u540c\u4e8e\u65b9\u6cd5\u4e00)\uff1a<\/p>\n<p>1\uff0e\u786e\u8ba4\u670d\u52a1\u5668\u5904\u4e8e\u5b89\u5168\u7684\u72b6\u6001\uff0c\u5728\u91cd\u65b0\u8bbe\u7f6eMySQL\u7684root\u5bc6\u7801\u7684\u671f\u95f4\uff0cMySQL\u6570\u636e\u5e93\u5b8c\u5168\u51fa\u4e8e\u6ca1\u6709\u5bc6\u7801\u4fdd\u62a4\uff0c\u4e0d\u8fde\u7f51\u64cd\u4f5c\u6700\u597d\uff0c\u5b9e\u5728\u4e0d\u884c\u6311\u4e2a\u597d\u65f6\u5019\uff0c\u64cd\u4f5c\u8981\u5feb<br \/>\n2\uff0e\u4fee\u6539MySQL\u7684\u767b\u5f55\u8bbe\u7f6e\uff1a<\/p>\n<pre># vi \/etc\/my.cnf<\/pre>\n<p>\u5728[mysqld]\u7684\u6bb5\u4e2d\u52a0\u4e0a\u4e00\u53e5\uff1askip-grant-tables<br \/>\n\u4f8b\u5982\uff1a<\/p>\n<pre>[mysqld]\r\ndatadir=\/var\/lib\/mysql\r\nsocket=\/var\/lib\/mysql\/mysql.sock\r\nskip-grant-tables<\/pre>\n<p>\u4fdd\u5b58\u5e76\u4e14\u9000\u51favi\u3002<br \/>\n3\uff0e\u91cd\u65b0\u542f\u52a8mysqld<\/p>\n<pre># \/etc\/init.d\/mysqld restart\r\nStopping MySQL: [ OK ]\r\nStarting MySQL: [ OK ]<\/pre>\n<p>4\uff0e\u767b\u5f55\u5e76\u4fee\u6539MySQL\u7684root\u5bc6\u7801<\/p>\n<pre>[root@vps ~]# mysql\r\nWelcome to the MySQL monitor. Commands end with ; or \\g.\r\nYour MySQL connection id is 2\r\nServer version: 5.1.61 Source distribution\r\nCopyright (c) 2000, 2011, Oracle and\/or its affiliates. All rights reserved.\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.<\/pre>\n<pre>mysql&gt; use mysql;\r\nReading table information for completion of table and column names\r\nYou can turn off this feature to get a quicker startup with -A\r\nDatabase changed<\/pre>\n<pre>mysql&gt; update user set password=password('jpuyy') where user = 'root';\r\nQuery OK, 2 rows affected (0.00 sec)\r\nRows matched: 2 Changed: 2 Warnings: 0<\/pre>\n<pre>mysql&gt; flush privileges;\r\nQuery OK, 0 rows affected (0.00 sec)\r\nmysql&gt; quit\r\nBye<\/pre>\n<p>5\uff0e\u5c06MySQL\u7684\u767b\u5f55\u8bbe\u7f6e\u4fee\u6539\u56de\u6765<\/p>\n<pre># vi \/etc\/my.cnf<\/pre>\n<p>\u5c06\u521a\u624d\u5728[mysqld]\u7684\u6bb5\u4e2d\u52a0\u4e0a\u7684skip-grant-tables\u5220\u9664<br \/>\n\u4fdd\u5b58\u5e76\u4e14\u9000\u51favi\u3002<br \/>\n6\uff0e\u91cd\u65b0\u542f\u52a8mysqld<\/p>\n<pre># \/etc\/init.d\/mysqld restart\r\nStopping MySQL: [ OK ]\r\nStarting MySQL: [ OK ]<\/pre>\n<p>\u9644\u52a0windows\u4e0b\u7684\u91cd\u7f6e\u65b9\u6cd5<\/p>\n<p>\u5f00\u59cb-\u8fd0\u884c-cmd<\/p>\n<p>net stop mysql<\/p>\n<p>\u7136\u540e\u8fdb\u5165\u5230mysql\u7684\u5b89\u88c5\u4f4d\u7f6e\uff0c\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4<\/p>\n<p>mysqld-nt.exe &#8211;skip-grant-tables<\/p>\n<p>\u518d\u6253\u5f00\u4e00\u4e2acmd\u7a97\u53e3<\/p>\n<p>\u8fd0\u884cmsyql -u root -p\uff0c\u4e0d\u7528\u8f93\u5165\u5bc6\u7801\u5373\u53ef\u8fdb\u5165<\/p>\n<p>&gt; use mysql<\/p>\n<p>&gt; UPDATE user SET Password=PASSWORD(&#8216;newpassword&#8217;) where USER=&#8217;root&#8217;;<\/p>\n<p>&gt;flush privileges;<\/p>\n<p>\u6700\u540e\u5728\u4efb\u52a1\u7ba1\u7406\u5668\u91cc\u5c06mysql-nt\u7684\u4efb\u52a1\u548c\u8fdb\u7a0b\u90fd\u505c\u6b62\u6389\uff08\u5982\u679c\u4e0d\u505c\u6389\u4f1a\u51fa\u73b0\u201cmysql\u670d\u52a1\u65e0\u6cd5\u542f\u52a8\u3002\u7cfb\u7edf\u51fa\u9519\u3002\u7cfb\u7edf\u53d1\u751f1067\u9519\u8bef\u3002\u8fdb\u7a0b\u610f\u5916\u4e2d\u6b62\u3002\u201d\uff09\uff0c\u63a5\u4e0b\u6765<\/p>\n<p>net start mysql<\/p>\n<p>\u5bc6\u7801\u91cd\u7f6e\u5b8c\u6210\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\u4e00\uff1a \u4e00\u4e2a\u4e2d\u5fc3:\u505c\u6b62\u670d\u52a1,\u8f7d\u5165\u5b89\u5168\u6a21\u5f0f killall -TERM mysqld \u7136\u540e mysqld &#8211;skip-grant-tables &amp; \u4e24\u4e2a\u57fa\u672c\u70b9\uff1a\u66f4\u65b0user\u8868\uff0c\u5237\u65b0\u6743\u9650 use mysql; update user set password=password(&#8220;newpass&#8221;) where user=&#8221;root&#8221;; flush privileges; \u5982\u679c\u4e0d\u65b9\u4fbf\u7528mysql\u7684cli\u754c\u9762\u4ea4\u4e92 \u8c03\u7528mysqladmin\u5373\u53ef mysqladmin -u root flush-privileges password &#8220;newpassword&#8221; &nbsp; \u65b9\u6cd5\u4e8c\uff08debian\u4eb2\u6d4b\uff09\uff1a \u76f4\u63a5\u4f7f\u7528\/etc\/mysql\/debian.cnf\u6587\u4ef6\u4e2d[client]\u8282\u63d0\u4f9b\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801 \u5907\u7528 mysql -u debian-sys-maint -p Enter password: &lt;\u8f93\u5165[client]\u8282\u7684\u5bc6\u7801&gt; mysql&gt; show databases; mysql&gt; use mysql; mysql&gt; show tables; \u8fd9\u4e2a\u65f6\u5019\u4f7f\u7528user\u8868 mysql&gt; UPDATE user SET Password=PASSWORD(&#8216;newpassword&#8217;) where [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[23],"class_list":["post-797","post","type-post","status-publish","format-standard","hentry","category-linux","tag-summary"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=797"}],"version-history":[{"count":11,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":1131,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/797\/revisions\/1131"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}