You can recover MySQL database server password with following five easy steps.
Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password
Step # 3: Connect to mysql server as the root user
Step # 4: Setup new root password
Step # 5: Exit and restart MySQL server
Here are commands you need to type for each step (login as the root user):
Step # 1 : Stop mysql service
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.
Step # 2: Start to MySQL server w/o password:
# mysqld_safe --skip-grant-tables &
Output:
[1] 5988 Starting mysqld daemon with databases from /var/lib/mysql mysqld_safe[6025]: started
Step # 3: Connect to mysql server using mysql client:
# mysql -u root
Output:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
Step # 4: Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stop MySQL Server:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld STOPPING server from pid file /var/run/mysqld/mysqld.pid mysqld_safe[6186]: ended [1]+ Done mysqld_safe --skip-grant-tables
Step # 6: Start MySQL server and test it
# /etc/init.d/mysql start
# mysql -u root -p
- Email this to a friend
- Printable version
- Rss Feed
- Last Updated: Dec/28/2006
{ 84 comments… read them below or add one }
THANKS!
SAVED MY ASS!
Thanks a lot!
I’ve been googling for 2 hours and your solution was the only one that worked!
thank you! i forgot my password and was afraid I had to reinstall mysql!. you saved me. props to you and msn search!
On most *nix systems as root (or with sudo) you can also do:
cat /root/.mysql_history|more
Which is very informative.
Nice :)
Hi,
When I try stop mysql on my server, I receive a error 1045. Access denied for user: ‘root@localhost’ (Using password: NO)
Thanks
HEllo,
This one alo can help you for it.
http://linux-tweaks.blogspot.com/2006/09/access-denied-for-user-rootlocalhost.html
This is great help, thanks for this posting!
i want free download of Recover MySQL root password
Brilliant guide – lifesaver!
thanks for this great post
Thanks! I’ve been looking at numerous other solutions and none of them worked. This one worked, no hassles.
Great tutorial.. it just worked fine
Coolness!!! thanks for this post! already bookmarked!!!hehehe..
Coolness!!! This site is really the best! I also got a ftpbackup script from here! the best how to’s, I wish you the best and I hope that you could add more!!!
I got the following error
ERROR! MySQL PID file could not be found!
do have any solution
Um… I’ve been trying to actually change the password for about 3 days now, and I tried this tutorial… No errors, but when I start the MySQL client and type in my password it just beeps and goes away :( Is there any other way?
Open X terminal and at shell prompt use command:
mysql -u root -p
You should able to see an error message.
Thanks for the help. This was just what I was looking for. I have no idea how I blew away my password, but at least this helped me get back in.
Thanks!
Murdock
THANK YOU!!!!!!!!!!!! THANK YOU!!!!!!!!!!!
Dude, you rock my world. shotalot
Yeah.. it is workin very well.. it saved me from formatting my Server… college 1……. :)..s o it works………..
Many thanks, this saved me a lot of time.
Greetings. Thank you so much. We are just getting our server up and running and working through some mysql issues. You saved me a lot of time and headaches. Dave
Thank you very much
I love you all. This is the only solution that worked not even de.mysql’s solution worked…
great, works exactly as shown. give the man a cigar!
Vivek,
does this affect the dbases / the rest of the users in any harmful way?
another relieved joomla user here as Im now back in charge of mysql thanks a lot!
Thank you.
God bless.
You saved my ass!!! I can’t thank you enough!
gr8 one! thanks.
I am using a windows op, how do I recover the password under Windows
I think I read this same article the last time my root acct got locked out. Thanks for hosting this page.
I’ve done everything exactly as it says , but still canot connect with my mysql server. I allways have this error: ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: YES)
Even when i do NOT use a password , it just not working! i tryed to reintall mysql through synaptic , but still the same shit… No difference. Can enyone give an advise?
Hi,
Can I remove an existing password following you guide, except that i leave this portion:
mysql> update user set password=PASSWORD(”NEW-ROOT-PASSWORD”) where User=’root’;
as this :
mysql> update user set password=PASSWORD(”") where User=’root’;
Would this work? I need to remove the password for a bit, for testing purposes…and then set the password again….any help/advise is much appreciated…
-nisha-
Hi again,
The problem I mentioned above, well, I tested it,and it works….thank you for the perfect guide ;-)
This is the i-can’t-remember-number-of-times that one of your articles has helped me… so, thanks for that too!
I tried all others, which failed!!!! This one works!!!! Thank you for making the instructions so simple to follow for us NON-LINUX Gurus. Much Thanks!
Thanks alot!! Also saved me some hours :)
Gleb, you need to use the unix shell as root to kill the mysql server process directly, then you can follow the mysql start without privileges command and get back in that way.
If you don’t know how to get a process list and send it a signal, you should read up just a little bit on that.
man ps
man kill
But something like:
ps aux | grep mysql
kill -TERM [processnumber# from command above]
(yes there is a one step command, but I personally ashew wildcards in my kill commands)
thank you very very much!
thanks for this clear tutorial
Thanks! Many thanks!
Good work. Thanks a alot!
Faisal
BIG TNX!!!
After staying idle most of the day since i messed up the database, this is the best thing that happened on this day
THANKS!!!
Useful and to the point!
Ko.
The gift that keeps on giving, 2 years and counting, this helped me out big time… Thanks!
Fantastic! thanks a lot!
great! good job :)
this is really worth printable…
Thank you, it works now.
thanks this worked perfectly!!
Thanks a ton. I was stuck since a very long time. Could not find anywhere but here it was very clear.
Thanks very much!
Bookmarked for future reference! Thanks for the very straightforward explanation, can’t think of a better way to do it!
Thank you very much! Saved some hours of reinstalling mysql.
Thank you. I’ve been trying using Toad and Password recovery tools but to no avail. This got it done!
Thank you very much. Windows users, you can do all of those commands from the command prompt, make sure you run it in admin mode, and change directory to where the mysql files are located, so when you run those commands it works. :)
Thank you , this is very helpful, as some one said it was the one excellent solution worked for me.
my day is better
Thanks a lot!
Its much more elegant than the solution in the official mysql reference.
It works — the very only one by far — Kubuntu 8.10
Description is crisp concise and foolproof
Thank You very much
I wish I knew howto tell google
Excellent!
Buy that person a beer! Or other meaningful beverage of choice.
Thanks!!
Thank you! Saved my ass too.
/etc/init.d/mysql stop
* Stopping MySQL database server mysqld [fail]
You ware going to need to fill in the gaps. If it fails then…….
amazing… thanks a lot!!
Thanks ever so much
thanx, wasted 2 hours googling and this method works,
Stephen :)
skip-grant-tables…. NICE!
Hi!
Wonderful guide. Congratulations!
Bye!
So Simple, yet so valuable. THANKS!
Very good, on ubuntu 9.04 mysqld 5.1 come installed with a mysterous password, I reseted it with this procedure and It works fine, thank you.
Thank you very much, I’ve waisted more than 2 hours trying to recover MySql password.
Thanks again :)
You saved me a lot of frustration, Thanks
omg, dude, you’re a genious….
Thank You..
Nice, thanks !
This worked really well. Thank you :)
Thanks!
It works gr8!
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU.
Most sincerely,
Darrell Goodman
Toronto, Canada
you are a ruddy hero.
thank you.
Tutoriais como esse deveriam ficar na wikipedia dos tutoriais!
Abraço,
This didn’t work for me. I now get the following when trying to log in: (I’m logged in as root):
ctru2:~ # mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
What does this mean, and how do I get around it?
Thanks!!!! It was really easy and worked like charm.
Server version: 5.0.51a-24 (Debian)
if you are using windows, you will still have the problem if you are using phpMyAdmin, open the config.inc.php, should be in your windows directory, change the password in there.
hi i want to know that how to remove or recover password which is on file when we open it in mysql it is asking for password how to remove them plz any one tell