MySQL root Password reset (Debian only)

Dieser Artikel ist in Englisch, da er auch für internationale Besucher hilfreich sein könnte. In Deutsch findet sich das Orginal hier: http://www.device-leben.de/mysql-root-passwort-reset-ohne-downtime-debian-only/551/

One of the most important passwords on database servers is the root password. In this tutorial I am going to show you how to reset a forgotten root password on debian machines without any downtimes.

We start by fetching the debian.cnf file from the MySQL config folder.

# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = <COPY THIS>
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
user     = debian-sys-maint
password = <COPY THIS>
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

The two <COPY THIS> blocks should be equal and you need to copy them.
Now, connect to the MySQL server using the following command:

$ mysql -udebian-sys-maint -p
Enter password:

Enter the copied password here, or just paste it.

Finally, run those two commands and you are all set:

UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;

Now, use quit; to terminate the MySQL shell session and have fun with the new root password.



Einen Kommentar schreiben