MySQL root password after installation

If you are wondering what the root password of MySQL is, here are the steps which will help you reset the same.

$ sudo apt install mysql-server
$ sudo cat /etc/mysql/debian.cnf

Note the lines which read:

user = debian-sys-maint
password = <SomePassword>

$ mysql -u debian-sys-maint -p
Enter password:  (Enter password <SomePassword> from above here)

mysql> USE mysql
mysql> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User             | Host      | plugin                |
+------------------+-----------+-----------------------+
| root             | localhost | auth_socket           |
| mysql.session    | localhost | mysql_native_password |
| mysql.sys        | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)

mysql>UPDATE mysql.user SET authentication_string=PASSWORD('new_password') where user='root';
(after selecting the appropriate database)
mysql> flush privileges;
mysql> commit;
mysql> exit

Restart the mysql service now

$ sudo service mysql restart

Login with the new password
$ mysql -u root -p

This should have reset the root password!

Leave a Reply

Your email address will not be published. Required fields are marked *