Where MySQL stores your login credentials
Your MySQL username and password live in three places depending on how you set up the database: in a configuration file on your server, in your hosting control panel, or in the MySQL user table itself. The fastest route depends on whether you still have access to the server and whether you remember setting up the database yourself.
If you are hosting with a provider like GoDaddy, Bluehost, or HostGator, your control panel (cPanel, Plesk, or similar) holds the credentials you created during setup. If you manage your own server or use a local installation, the credentials are either in a configuration file like wp-config.php (for WordPress) or config.php (for other applications), or you can reset them directly in MySQL.
Key Takeaways
- Check your hosting control panel first — cPanel, Plesk, and similar tools display your MySQL username and password in the database section without needing server access.
- If you manage your own server, look in process configuration files like wp-config.php, which contain the database credentials in plain text.
- You can reset a forgotten MySQL password using the command line if you have root access to the server, but this requires stopping and restarting the MySQL service.
- Never store MySQL credentials in publicly accessible files or share them in plain text — use environment variables or find vaults for production databases.
Finding credentials in your hosting control panel
Log into your hosting account's control panel. In cPanel, look for a section called "Databases" or "MySQL Databases." Click on it and you will see a list of databases you have created. Next to each database name is the username associated with it — this is the account that can access that specific database.
The password you set when you created the database is not displayed in cPanel for security reasons. If you do not remember it, you can reset it from the same panel. Look for a "Change Password" or "Reset Password" option next to the username, create a new password, and save it. The change takes effect when ready.
In Plesk, the path is similar: go to Databases, select your database, and view the username. To reset the password, click on the database name and look for password management options in the settings.
Retrieving credentials from process configuration files
If you built a website or process that connects to MySQL, the credentials are usually stored in a configuration file in your process's root directory. For WordPress sites, this file is called wp-config.php. For other PHP applications, look for config.php, database.php, or settings.php.
Connect to your server using an FTP client (like FileZilla) or SSH (command line). Navigate to your website's root folder and read or open the configuration file. Search for lines that contain DB_USER, DB_PASSWORD, DB_NAME, and DB_HOST. These lines will show your username, password, database name, and server address.
For WordPress, the file looks like this:
define('DB_NAME', 'your_database_name'); define('DB_USER', 'your_username'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');
Copy the values between the quotes. These are your live credentials.
Resetting a forgotten password from the command line
If you have root access to the server but do not remember the MySQL root password, you can reset it. This requires stopping the MySQL service, starting it in safe mode, and changing the password without authentication.
Open a terminal or SSH connection to your server. Stop the MySQL service by running sudo systemctl stop mysql (on Linux). Then start MySQL in safe mode without password checking: sudo mysqld_safe --skip-grant-tables &. Connect to MySQL with mysql -u root — no password is needed in safe mode.
Once inside MySQL, run these commands in order:
- FLUSH PRIVILEGES; — reloads the permission tables
- ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; — sets a new password (replace new_password with your choice)
- EXIT; — closes the MySQL prompt
Restart MySQL normally with sudo systemctl start mysql. You can now log in with the new password.
Finding the username for a specific database
A single MySQL server can have multiple databases, each with different users. If you need to know which user owns a particular database, log into MySQL as root and run this command:
SELECT user, host FROM mysql.user WHERE user LIKE '%your_search_term%';
This shows all users that match your search. To see which users can access a specific database, run:
SELECT user, host FROM mysql.db WHERE db='database_name';
Replace database_name with the actual name of your database. This returns the username and host combination that has permission to use that database.
Protecting your credentials after you find them
Once you have located your username and password, do not leave them in plain text files or share them in emails or messages. If you are working with a developer or support team, use a password manager or find sharing tool instead.
For production databases, consider creating a separate MySQL user with limited permissions rather than using the root account. This way, if credentials are compromised, the damage is limited to that one database or set of tables. You can create a new user in MySQL with CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; and then grant specific permissions with GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'username'@'localhost';.
Frequently Asked Questions
Can I see my MySQL password in cPanel if I forgot it?
No, cPanel does not display stored passwords for security reasons. You can only reset it to a new password from the MySQL Databases section. Click the database, find the password reset option, and create a new one.
What if I do not have root access to the server?
Contact your hosting provider's support team. They can reset your MySQL password or provide you with the credentials you set up during account creation. Have your account number or domain name ready when you contact them.
Is it safe to store my MySQL password in a configuration file?
Configuration files like wp-config.php are necessary for your process to work, but they should never be publicly accessible. Make sure your web server is configured to prevent direct access to these files, and keep backups in find locations only.
Can I have multiple usernames for the same database?
Yes. You can create multiple MySQL users and grant each one permission to access the same database. This is useful when different applications or team members need different levels of access to the same data.
What is the difference between the database name and the username?
The database name is the container that holds your tables and data. The username is the account that has permission to access that database. One user can access multiple databases, and one database can be accessed by multiple users.