{"id":683,"date":"2012-01-23T08:20:37","date_gmt":"2012-01-23T16:20:37","guid":{"rendered":"http:\/\/blog.portnumber53.com\/?p=683"},"modified":"2012-01-23T08:20:37","modified_gmt":"2012-01-23T16:20:37","slug":"mysql-recover-root-password","status":"publish","type":"post","link":"https:\/\/blog.portnumber53.com\/index.php\/2012\/01\/23\/mysql-recover-root-password\/","title":{"rendered":"MySQL: Recover root password"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div># mysql -u root<\/div>\n<div>Enter password:<\/div>\n<div>ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO)<\/div>\n<div>&nbsp;<\/div>\n<div>\n<div># mysql -u root -p<\/div>\n<div>Enter password:<\/div>\n<div>ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>1 Stop MySQL server:<\/p>\n<p># service mysql start<\/p>\n<p>&nbsp;<\/p>\n<p>2. Add &#8211;skip-grant-tables to your mysql start script<\/p>\n<p># nano \/etc\/rc3.d\/S20mysql<\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>&nbsp;<\/p>\n<div>case &quot;${1:-&#39;&#39;}&quot; in<\/div>\n<div>&nbsp; &#39;start&#39;)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; sanity_checks;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; # Start daemon<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; log_daemon_msg &quot;Starting MySQL database server&quot; &quot;mysqld&quot;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; if mysqld_status check_alive nowarn; then<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;log_progress_msg &quot;already running&quot;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;log_end_msg 0<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; else<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Could be removed during boot<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test -e \/var\/run\/mysqld || install -m 755 -o mysql -g root -d \/var\/run\/mysqld<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Start MySQL!<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/usr\/bin\/mysqld_safe <span style=\"color:#008000;\">&#8211;skip-grant-tables<\/span>&nbsp;&gt; \/dev\/null 2&gt;&amp;1 &amp;<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # 6s was reported in #352070 to be too few when using ndbcluster<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do<\/div>\n<div>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/div>\n<div>&nbsp;<\/div>\n<p>&nbsp;<\/p>\n<p>3. Start your server again<\/p>\n<p>&nbsp;<\/p>\n<p># service -mysql start<\/p>\n<p>&nbsp;<\/p>\n<p>4. Log in using mysql root user without entering a password:<\/p>\n<p># mysql -u root mysql<\/p>\n<p>&nbsp;<\/p>\n<p>And let&#39;s do the actual reset:<\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;&#8212;-<\/p>\n<p>&nbsp;<\/p>\n<div>Reading table information for completion of table and column names<\/div>\n<div>You can turn off this feature to get a quicker startup with -A<\/div>\n<div>&nbsp;<\/div>\n<div>Welcome to the MySQL monitor. &nbsp;Commands end with ; or \\g.<\/div>\n<div>Your MySQL connection id is 35<\/div>\n<div>Server version: 5.1.49-3 (Debian)<\/div>\n<div>&nbsp;<\/div>\n<div>Copyright (c) 2000, 2010, Oracle and\/or its affiliates. All rights reserved.<\/div>\n<div>This software comes with ABSOLUTELY NO WARRANTY. This is free software,<\/div>\n<div>and you are welcome to modify and redistribute it under the GPL v2 license<\/div>\n<div>&nbsp;<\/div>\n<div>Type &#39;help;&#39; or &#39;\\h&#39; for help. Type &#39;\\c&#39; to clear the current input statement.<\/div>\n<div>&nbsp;<\/div>\n<div>mysql&gt; update user set password=Password(&#39;1234&#39;) where user=&#39;root&#39;;<\/div>\n<div>Query OK, 1 row affected (0.00 sec)<\/div>\n<div>Rows matched: 1 &nbsp;Changed: 1 &nbsp;Warnings: 0<\/div>\n<div>&nbsp;<\/div>\n<div>mysql&gt; flush privileges;<\/div>\n<div>Query OK, 0 rows affected (0.00 sec)<\/div>\n<div>&nbsp;<\/div>\n<div>mysql&gt; exit<\/div>\n<div>Bye<\/div>\n<div>&nbsp;<\/div>\n<div>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/div>\n<div>&nbsp;<\/div>\n<div>5. Stop the server one more time<\/div>\n<div>&nbsp;<\/div>\n<div># service mysql stop<\/div>\n<div>&nbsp;<\/div>\n<div>6. Remove &#8211;skip-grant-table from your mysql startup command<\/div>\n<div>&nbsp;<\/div>\n<div># nano \/etc\/rc3.d\/S20mysql<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>7. Start your mysqlserver<\/div>\n<div>&nbsp;<\/div>\n<div># service mysql start<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>8. Enjoy your server:<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/div>\n<div>\n<div>root@debian:~# mysql -u root -p<\/div>\n<div>Enter password:<\/div>\n<div>Welcome to the MySQL monitor. &nbsp;Commands end with ; or \\g.<\/div>\n<div>Your MySQL connection id is 35<\/div>\n<div>Server version: 5.1.49-3 (Debian)<\/div>\n<div>&nbsp;<\/div>\n<div>Copyright (c) 2000, 2010, Oracle and\/or its affiliates. All rights reserved.<\/div>\n<div>This software comes with ABSOLUTELY NO WARRANTY. This is free software,<\/div>\n<div>and you are welcome to modify and redistribute it under the GPL v2 license<\/div>\n<div>&nbsp;<\/div>\n<div>Type &#39;help;&#39; or &#39;\\h&#39; for help. Type &#39;\\c&#39; to clear the current input statement.<\/div>\n<div>&nbsp;<\/div>\n<div>mysql&gt;<\/div>\n<div>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/div>\n<div>&nbsp;<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp; &nbsp; # mysql -u root Enter password: ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO) &nbsp; # mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES) &nbsp; &nbsp; 1 Stop MySQL server: # service mysql start&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/blog.portnumber53.com\/index.php\/2012\/01\/23\/mysql-recover-root-password\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[253,287,295],"class_list":["post-683","post","type-post","status-publish","format-standard","hentry","category-linux","tag-mysql","tag-recover","tag-root-password"],"_links":{"self":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/comments?post=683"}],"version-history":[{"count":0,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/683\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/media?parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/categories?post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/tags?post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}