Resetting the root MySQL Password on Debian 7.11

The easiest way to reset the root users mysql password on most Debian systems is to use the debian-sys-maint user. The login details for which can be found below:

/etc/mysql/debian.cnf

With the password found in there, you should be able to log in as such.

[email protected]:~# mysql -u debian-sys-maint -p'4St4LWE97I2E'

Now once you’re logged into MySQL, change the root users password like follows:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Tkh#4WBI$6%%');
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Quit MySQL by typing exit or simply ‘\q‘:

mysql> \q
Bye

Then test the login works:

[email protected]:~# mysql -u root -p'Tkh#4WBI$6%%'

Assuming that worked, you might want to create a ~/my.cnf file for easier logins in the future.

[email protected]:~# vim ~/.my.cnf

Replace with your password.

[email protected]:~# cat ~/.my.cnf
[client]
user=root
password='Tkh#4WBI$6%%'

Make sure only the intended user can access. Here this is root.

[email protected]:~# chmod -v 600 ~/.my.cnf
mode of `/root/.my.cnf' changed from 0644 (rw-r--r--) to 0600 (rw-------)

Now you should be able to access MySQL as the root user simply with “mysql“:

[email protected]:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1692852
Server version: 5.5.60-0+deb7u1-log (Debian)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Be the first to comment

Leave a Reply