How to find out the MySQL root password
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If you have forgotten the MySQL root password, the important point is that you usually cannot "discover" the current password in plain text from MySQL itself. Proper systems do not expose stored passwords for retrieval. In practice, the job is to check whether the password is already stored in a legitimate credential source and, if not, reset it safely.
First: Check Legitimate Credential Sources
Before attempting a reset, look in the places where the password may have been stored intentionally during installation or deployment:
- your team's secret manager
- deployment variables in CI or infrastructure code
- a local
~/.my.cnffile - application configuration files
- password vault entries
- installation notes or bootstrap scripts
For example, a local client config might contain credentials:
If such a file exists, make sure it is actually the current password before changing anything:
In some installation flows, MySQL prints a temporary root password to logs. If you know the server was initialized that way, the installation log may be the right place to check. That is not the same as extracting the existing password from the database after the fact.
When You Need to Reset It
If you do not have a valid credential source, resetting the password is the normal administrative path. The exact steps vary by platform and MySQL version, but the overall process is consistent:
- stop the MySQL server
- start it in a recovery mode that skips normal grant checks
- connect locally
- set a new password
- restart the server normally
On many systems, stopping the service looks like this:
Then start MySQL in a recovery mode from a controlled shell session:
Now connect without the old password:
Then set a new password:
After that, stop the recovery instance and restart MySQL normally.
Verify the New Password Immediately
Once the server is back in its normal mode, test the new login right away:
If the login works, update any dependent systems such as:
- local application
.envfiles - secrets managers
- backup jobs
- monitoring agents
- deployment pipelines
Failing to rotate those references is one of the fastest ways to break an environment after a password reset.
Be Careful With Managed Services
If your database is hosted in a managed platform such as Amazon RDS, Cloud SQL, or Azure Database, do not use local server recovery steps intended for a self-managed MySQL instance. Managed services expose password reset flows through their control plane instead.
That distinction matters because a lot of generic internet advice assumes you control the MySQL process directly. On managed infrastructure, you often do not.
Treat Root as an Emergency Account
A good long-term fix is not just resetting the password but reducing how often root is used. In many applications, root should be reserved for setup and emergency administration. Day-to-day services should have narrower accounts with only the permissions they actually need.
That way, forgetting or rotating the root password does not break the whole system.
Common Pitfalls
The most common mistake is assuming MySQL can reveal the current root password. Secure systems do not work that way; the correct response is to use stored credentials or reset the password.
Another mistake is following reset instructions on a managed database service where you do not control the underlying MySQL daemon. Use the provider's reset mechanism instead.
Developers also sometimes reset the password successfully but forget to update applications, scripts, or secret stores that still reference the old value.
Finally, be careful with recovery mode. Running with grant tables disabled should be a temporary, local administrative action, not a normal operating state.
Summary
- You usually cannot retrieve the current MySQL root password in plain text from MySQL.
- First check legitimate credential stores such as vaults, config files, or installation logs.
- If the password is truly unknown, reset it instead of trying to "find" it.
- Use a provider-specific reset path for managed database services.
- After a reset, update every dependent system that uses the old credential.
Related reading
- how to find size of database, schema, table in redshift
- How to find the index of an element in a TreeSet?
- How to find the mysql data directory from command line in windows
- How to fix Error executing DDL alter table events drop foreign key FKg0mkvgsqn8584qoql6a2rxheq via JDBC Statement
- How to find unused Amazon EC2 security groups
- How to fix bad certificate error in traefik 2.0?
- How to fix Hibernate LazyInitializationException failed to lazily initialize a collection of roles, could not initialize proxy - no Session
- How to fix Incorrect string value errors?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.