Locked out of your own database? It happens to everyone once. The recovery procedure is straightforward — the key is re-securing the server immediately afterwards.
Key Points
- Stop MySQL: sudo systemctl stop mysql
- Start in recovery mode: sudo mysqld_safe --skip-grant-tables --skip-networking &
- Log in without password: mysql -u root
- Reset: FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPass!';
- Restart MySQL normally and verify the new login
- skip-grant-tables disables all security — never leave it running
.png)