{"id":190,"date":"2010-01-23T00:47:17","date_gmt":"2010-01-22T13:47:17","guid":{"rendered":"http:\/\/howden.net.au\/thowden\/2010\/01\/mysql-root-password-fails-or-forgotten\/"},"modified":"2010-01-23T00:47:17","modified_gmt":"2010-01-22T13:47:17","slug":"mysql-root-password-fails-or-forgotten","status":"publish","type":"post","link":"https:\/\/howden.net.au\/thowden\/2010\/01\/mysql-root-password-fails-or-forgotten\/","title":{"rendered":"MySQL root password fails or forgotten"},"content":{"rendered":"<p>I had setup a new Ubuntu server with MySQL and during the install I was sure I knew the password I set for the mysql root user.<\/p>\n<p>So I then setup webmin and went to access mysqladmin and it failed. I then tried at the command line and it failed.<\/p>\n<p>So I am stuck with a running but inaccessible mysql server.<\/p>\n<p>This <a href=\"http:\/\/www.trap17.com\/forums\/Mysql-s-Default-Root-Password-t31717.html\">thread at Trap17<\/a> was the one that helped but it was missing a couple of key points.<\/p>\n<p>I&#8217;ll repeat it here in case the link goes away in the future. If you are using Ubuntu without a root password you will need to prefix some of the following with the &#8216;sudo&#8217; command so that they will run ok.<\/p>\n<p>First stop mysql<\/p>\n<blockquote><p>\/etc\/init.d\/mysql stop<\/p><\/blockquote>\n<p>Then run this command that basically says &#8220;run mysql without password control&#8221;<\/p>\n<blockquote><p>mysqld_safe &#8211;skip-grant-tables &amp;<\/p><\/blockquote>\n<p>With my server this resulted in not returning to the command prompt. Press &#8220;Enter&#8221; to get the command prompt again.<br \/>\nThen open up mysql for a mysql prompt<\/p>\n<blockquote><p>mysql -u root -p<\/p><\/blockquote>\n<p>Which should result in a mysql&gt;  command prompt<\/p>\n<p>From the original post this next command appears redundant on Ubuntu so skip this one. <em>mysql client &#8211; mysql -u root<\/em><\/p>\n<p>The next command is done at the mysql prompt and again I differ from the original post<\/p>\n<blockquote><p>use mysql;<\/p><\/blockquote>\n<p>Note the semi-colon to complete the command. If you do copy and paste the two lines successfully then skipping the semi-colon on the first line is ok, but I like most people will initially try to do it a line at a time so I think it is clearer to execute as a sequence.<\/p>\n<p>The next command sets up your new password and you need to edit this line with your new password and your relevant user account name.<\/p>\n<blockquote><p>update user set password=PASSWORD(\u201dNEW-ROOT-PASSWORD\u201d) where User=\u2019root\u2019;<\/p><\/blockquote>\n<p>Ok, so now you possibly have an error. Depending on the way you held your lips you may or may not have the correct syntax copied to your command line. I am not sure if this is consistent with all browsers and all telnet clients but I use PuTTy and when I copy\/paste the above from the original thread I get this<\/p>\n<blockquote><p>update user set password=PASSWORD(.NEW-ROOT-PASSWORD.) where User=.root.;<\/p><\/blockquote>\n<p>Note that the quote marks in the command were converted to a &#8216;.&#8217; (period) character and when I hit the enter key I got an error<\/p>\n<blockquote><p>ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#8221; at line 1<\/p><\/blockquote>\n<p>So if you check your syntax and make sure you have the quotes correctly placed then it will work fine.<\/p>\n<p>Finish up by closing the mysql command line with &#8216;exit&#8217; and stop \/ start mysql to get it to use passwords again.<\/p>\n<blockquote><p>\/etc\/init.d\/mysql stop<\/p><\/blockquote>\n<blockquote><p>\/etc\/init.d\/mysql start<\/p><\/blockquote>\n<p>And that should get your account running again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Changing the MySQL root password when you cannot recall what it was.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10],"tags":[68],"class_list":["post-190","post","type-post","status-publish","format-standard","hentry","category-linux-servers-and-software","category-mysql","tag-mysql-root-password-fails-forgotten"],"_links":{"self":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":0,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"wp:attachment":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}