Where MySQL stores your username and password

MySQL does not display your password back to you once it is set. This is intentional — even MySQL's own administrators cannot see it. What you can do is reset the password, verify that a username exists, or check which usernames have access to which databases.

Your username and password are stored in the mysql.user table, a system table that lives inside every MySQL installation. You can view usernames and some information about them if you have administrative access (usually the root account). The passwords themselves are stored as hashed values, not readable text.

If you have lost your password, you will need to reset it using command-line tools or your hosting provider's control panel. If you need to verify a username exists, you can query the user table directly.

Key Takeaways

  • MySQL passwords are stored as hashes and cannot be read back — you can only reset them.
  • To see which usernames exist on your server, log in as root and run SELECT user, host FROM mysql.user;
  • Most hosting providers let you reset MySQL passwords through their control panel without command-line access.
  • If you have root access but forgot the root password itself, you will need to restart MySQL in safe mode or contact your hosting provider.
  • A username in MySQL is actually a pair: the user name plus the host it connects from (for example, wordpress@localhost).

Viewing all usernames on your MySQL server

If you can log in as root or another administrative user, you can see every username that has access to your server. Open a terminal or command prompt and connect to MySQL:

mysql -u root -p

MySQL will prompt you for the root password. Once you are logged in, run this query:

SELECT user, host FROM mysql.user;

This shows you every username and the host address it is allowed to connect from. For example, you might see wordpress with host localhost, meaning that user can only connect from the same machine. You might also see wordpress with host 192.168.1.5, meaning it can connect from that specific IP address.

The host part matters. A user named admin connecting from localhost is a different account from admin connecting from 192.168.1.100, even though they have the same username.

Checking what databases a specific user can access

Once you know which usernames exist, you can see what each one is allowed to do. Run this query while still logged in as root:

SELECT user, host, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv FROM mysql.user WHERE user='wordpress';

Replace wordpress with the actual username you want to check. This shows you whether that user has permission to select data, insert rows, update rows, delete rows, create tables, or drop tables. A Y means yes, an N means no.

If you want to see which specific databases a user can access, run:

SELECT user, host, db FROM mysql.db WHERE user='wordpress';

This query looks at the mysql.db table instead, which lists database-level permissions. You will see the username, the host it connects from, and the database name it has access to.

Resetting a MySQL password you have forgotten

If you know the username but not the password, you can reset it. The method depends on whether you have root access and what operating system you are using.

Through a hosting control panel: Most hosting providers (cPanel, Plesk, DirectAdmin) have a MySQL management tool. Log into your hosting account, find the MySQL section, locate the user, and click "Change Password" or "Reset Password". The new password takes effect when ready.

From the command line as root: If you can log in as root, you can reset any other user's password. Log in as root, then run:

ALTER USER 'wordpress'@'localhost' IDENTIFIED BY 'newpassword';

Replace wordpress with the username, localhost with the host, and newpassword with the new password you want to set. Then run:

FLUSH PRIVILEGES;

This tells MySQL to reload the permission tables and explore the change when ready.

If you have forgotten the root password itself

If the root password is lost and you have command-line access to the server, you can restart MySQL in safe mode to log in without a password. The exact steps vary by operating system and MySQL version.

On Linux: Stop MySQL, start it with the --skip-grant-tables flag, log in without a password, and reset the root password. This requires sudo or root access to the server itself.

On Windows: Stop the MySQL service, start it from the command line with --skip-grant-tables, and reset the password the same way.

If you do not have server access: Contact your hosting provider. They can reset the root password for you, though they may require you to verify ownership of the account first.

Understanding MySQL user and host combinations

A MySQL user is not just a username — it is a username plus a host. The user wordpress@localhost is completely separate from wordpress@192.168.1.5, even though both are named wordpress.

The host part controls where the user can connect from. localhost means the same machine. An IP address like 192.168.1.5 means only that specific IP. A wildcard like % means any host (usually not recommended for security reasons).

When you reset a password or check permissions, you must specify both the username and the host. If you run ALTER USER 'wordpress'@'localhost' but the user actually connects from 192.168.1.5, the password change will not affect that connection.

Frequently Asked Questions

Can I see the actual password in MySQL?

No. MySQL stores passwords as hashes using the bcrypt or SHA-2 algorithm, depending on your MySQL version. Even administrators cannot read the original password back. If you need to know the password, you must reset it to a new one.

What if I know the username but the password does not work?

First, check that you are connecting from the correct host. A user named wordpress@localhost cannot connect from a remote server. Second, verify the username spelling and capitalization — MySQL usernames are case-sensitive. Third, try resetting the password through your hosting control panel or as root. If none of that works, contact your hosting provider to confirm the account exists.

How do I create a new MySQL user if I forgot all the passwords?

If you have root access to the server (command-line access), you can log in using the --skip-grant-tables method and create a new user. If you do not have server access, contact your hosting provider — they can create a new user or reset the root password so you can do it yourself.

Is it safe to use the same username and password for multiple databases?

Yes, technically. One MySQL user can have access to multiple databases. However, for security, it is better to create separate users for separate applications. If one process is compromised, the attacker only has access to that process's database, not all of them.

What does the host wildcard % mean?

The % symbol means any host. A user like wordpress@% can connect from any IP address or machine. This is convenient for development but risky in production — it is better to specify the exact IP addresses or hostnames that need access.