I’ve recently found myself in that awkward situation where I’ve chosen a (very) secure password for a root MySQL user and I’ve forgotten it. I suppose its the most secure password I’ve had then because even I cant use it to login to the MySQL database – not that you should be using a root account under any circumstances – this was debugging.
I’ve had this happen before and I’ve used the
trick that stops the MySQL server, starts it up with no password, allows you to change the password, then stop and restart the server with the new password in force.
Ideally I wanted no downtime (even for those few precious seconds). As usual, google ended up pointing (to me) to a unknown way to reset the root password using another account that has full root privileges in a standard Ubuntu install.
Full credit to https://www.configserverfirewall.com/ubuntu-linux/reset-mysql-root-password-ubuntu/, and the main parts are only reproduced here in case the original site goes offline.
The debian-sys-maint user account is an administrative user account automatically created when installing MySQL Server on Ubuntu and this user have full access to all databases.Quote from https://www.configserverfirewall.com/ubuntu-linux/reset-mysql-root-password-ubuntu/https://www.configserverfirewall.com/ubuntu-linux/reset-mysql-root-password-ubuntu/
This means that viewing the debian.cnf file using cat
sudo cat /etc/mysql/debian.cnf
nets us directly the login details including password for this account. Looking under
user = debian-sys-maint
password = LongAndRandomPassword
so, using these details, a a quick
mysql -udebian-sys-maint -p
FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewVerySecurePassword'; FLUSH PRIVILEGES;
nets you with an uninterrupted uptime MySQL password reset.
Now. To read about this account that has MySQL Root Privileges that I’ve never noticed before.