You’re SSH’d into your Ubuntu server. You run mysql -u root -p, type your password, and hit Enter. The response: Access denied. You try again. Same result. You check your notes, your password manager, that config file you saved somewhere, nothing works. Now you’re locked out of your own database and need to recover your MySQL Root Password.
Sound familiar? You’re not alone. Forgetting the MySQL root password is one of those things that happens to almost every developer or sysadmin at some point. The database is running, the data is there, but you cannot get in.
The good news: resetting it is straightforward, even if it feels intimidating the first time. You don’t need to reinstall anything. You don’t need to lose data. What you need is about 10 minutes, a handful of commands, and a clear sequence of steps.
This guide walks you through every scenario, changing a password you know, resetting one you’ve forgotten, handling the --skip-grant-tables method properly, and updating your applications afterward so nothing breaks. I’ve tested these steps on Ubuntu 22.04 and Ubuntu 24.04, and the process is similar on both versions.
TL;DR
- You can reset a forgotten MySQL root password by starting MySQL with --skip-grant-tables, then running SQL password commands
- You can change an existing password with a single ALTER USER statement while normally logged in
- Always stop websites/applications pointing to the database before resetting, they will lose connection during the process
- After resetting, update any application config files that store the old MySQL password
- For a server management experience that takes care of these automatically, explore ServerAvatar
- If your server is managed through ServerAvatar, you can update the database root password directly from the panel.
Understanding MySQL Root Access on Ubuntu
Before changing anything, it’s important to know what the MySQL root account actually is and how it differs from the Linux root user.
Before proceeding, make sure your server is actually running MySQL rather than MariaDB. Although the two database systems are closely related, there are important differences in features, compatibility, and administration. See our MariaDB vs MySQL comparison for a detailed breakdown.
MySQL root vs. Linux root: The MySQL root account is a database administrator account, separate from the Linux system root user.
MySQL root is a separate database-level administrator with full control over all databases, users, and permissions on your MySQL instance.
MySQL Authentication on Ubuntu
Ubuntu uses a plugin-based authentication system for MySQL. The authentication method configured for the root account determines how you can log in and reset its password. Common authentication methods include:
-
auth_socket
- Links MySQL authentication to your Linux system user.
- You can log in as MySQL root only when you’re already the Linux root user.
-
mysql_native_password
- Uses a stored password hash for authentication.
- A password is required to access the MySQL root account.
-
caching_sha2_password
- Also relies on a stored password hash.
- Authentication requires the MySQL root password.
MySQL supports multiple authentication plugins, which determine how credentials are verified when a user connects.
Check the Current Authentication Method
To find out which authentication method your MySQL root account is currently using, run:
SELECT user, host, plugin FROM mysql.user WHERE user = 'root';
The result will show the authentication plugin configured for the root user:
- auth_socket – You need sudo to log in as MySQL root from Linux.
- caching_sha2_password – You need the MySQL root password.
- mysql_native_password – You need the MySQL root password.
Knowing the authentication method is important because it determines how you access MySQL and how you reset the root password.
MySQL Authentication Methods Compared
Read Full Article: https://serveravatar.com/change-reset-mysql-root-password


Top comments (0)