MySQL: Reset root password on Debian based distros
Posted: Sun Aug 17, 2008 4:34 pm
[PROBLEM]
I've locked myself out of my MySQL, because I've forgotten my mysql-root password.
I didn't want to shutdown the MySQL server in order to follow general guides for resetting the password, like this one:
http://www.cyberciti.biz/tips/recover-m ... sword.html
[SOLUTION]
On Debian systems, package scripts sometimes need to initialize database things - so the package system needs a mysql-user with administrator priviledges.
This user is called "debian-sys-maint" - and its password is randomly generated during installation time and can be found in /etc/mysql/debian.cnf
Now, you can use the debian-sys-maint account to log in:
(the "--quick" option is important, otherwise the new root password would be stored in your ~/.mysql_history)
Now within the mysql terminal, type the following to reset the password:
That's it. You should now be able to login as mysql-root using your new password.
No service restart, no nothing. perfect!
I've locked myself out of my MySQL, because I've forgotten my mysql-root password.
I didn't want to shutdown the MySQL server in order to follow general guides for resetting the password, like this one:
http://www.cyberciti.biz/tips/recover-m ... sword.html
[SOLUTION]
On Debian systems, package scripts sometimes need to initialize database things - so the package system needs a mysql-user with administrator priviledges.
This user is called "debian-sys-maint" - and its password is randomly generated during installation time and can be found in /etc/mysql/debian.cnf
Now, you can use the debian-sys-maint account to log in:
Code: Select all
mysql --user=debian-sys-maint --quick --password
Now within the mysql terminal, type the following to reset the password:
Code: Select all
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;
No service restart, no nothing. perfect!