FAQ: Change forgotten or lost MySQL root password

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

Question: I forgot root password for MySQL DBE. How to reset or recover it? PLEASE HELP!

Answer: Below is simple algorithm to reset MySQL root password in Linux, FreeBSD, OpenBSD and other Unix like operating systems:

1. Stop MySQL server process by one of the following commands:
# /etc/init.d/mysqld stop
# killall -9 mysqld
# kill `cat /mysql-data-directory/host_name.pid`
# mysqladmin shutdown

To check if mysqld is killed run "ps ax | grep mysqld" that should show no mysqld instances.

2. Start MySQL server without password protection:
$ mysqld --skip-grant-tables --user=root &
or
$ mysqld --skip-grant-tables &

3. Login to MySQL console by "mysql -u root" and set up new password with the following mysql commands:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;

4. Now you should be able to connect MySQL with new password.

P.S. There is alternative 2 and 3 steps:

2. Create text file /tmp/init.mysql with the following contents:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');

3. Start MySQL with command:
# mysqld_safe --init-file=~/mysql-init &

Hope it helps!!!

 
 
» You might also be interested in the following articles:
Quick copy/paste MySQL Replication Manual
Why use SUDO instead of SU?
FAQ: How to install and configure MySQL cluster?
Sun acquires MySQL AB
Encryption files with GPG without user intervention (batch)



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!


Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem Nosulchik (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››