- 1 1. Introduction
- 2 2. How to Check the MySQL Initial Password
- 3 3. What to Do If You Forgot the Password
- 4 4. Check and Configure Password Policy
- 5 5. Troubleshooting
- 6 6. FAQ
- 6.1 Q1: What should I do if I can’t find the initial password?
- 6.2 Q2: Why can’t I log in even after resetting the password?
- 6.3 Q3: Is it possible to disable the password policy?
- 6.4 Q4: What should I do if I get an error during the password reset?
- 6.5 Q5: If the password is shared with other administrators, will changing it have an impact?
- 7 7. Summary
1. Introduction
MySQL is an essential tool used in many web applications and database systems. However, during operations, it’s not uncommon to run into situations like “I forgot the password” or “I don’t know the initial password.” These issues can significantly affect workflow and database security.
In this article, we’ll explain in detail—so even beginners can follow—how to check MySQL’s initial password and how to reset it if you’ve forgotten it. We also provide procedures for both Linux and Windows so you can follow the steps that match your environment.
In the second half of the article, we’ll also cover how to check and change password policy settings, as well as how to handle common errors. This will help you gain a comprehensive understanding of how to operate MySQL more safely and efficiently.
By reading this article, you’ll be able to understand and put the following into practice:
- How to check MySQL’s initial password
- How to reset the password if you forgot it (for both Linux and Windows)
- How to troubleshoot issues and configure password policy settings
Read through to the end and set up an environment where you can use MySQL with confidence.
2. How to Check the MySQL Initial Password
When you install MySQL for the first time, an initial (temporary) password may be set by default. If you can find this initial password, the first login and the password change process will go much more smoothly. In this section, we’ll explain specific ways to check the initial password on both Linux and Windows.
2.1 How to Check the Initial Password on Linux
On Linux, you can check the initial password by reviewing the log file generated after installing MySQL. Follow the steps below.
Steps:
- Open a terminal.
- Run the following command to view the log file contents.
sudo cat /var/log/mysqld.log | grep 'temporary password'- The command output will show the initial password along with the text “temporary password.”
- Example:
2025-01-19T10:45:32.123456Z 1 [Note] A temporary password is generated for root@localhost: Abc12345! - In this case,
Abc12345!is the initial password.
- Write down the initial password and use it when logging in to MySQL.
Notes:
- The initial password is randomly generated for security reasons.
- After the first login, you’ll be required to change the password, so be sure to set a new one.
2.2 How to Check the Initial Password on Windows
On Windows, you can check the initial password from the log file generated during the initial MySQL setup, or from the installer screen. Use the steps below as a reference.
Steps:
- Open the directory where MySQL is installed.
- The default path is usually something like this:
C:\ProgramData\MySQL\MySQL Server X.X\Logs
*X.X indicates the MySQL version number.
- Look for a file named
mysqld.log. - Open the log file with Notepad or any text editor.
- Search within the file for the keyword “temporary password.”
- The initial password will be shown along with the text “root@localhost.”
- Write down the initial password and use it when logging in to MySQL.
Additional note:
- Depending on the installer, the initial password may be shown on-screen during installation. In that case, it’s recommended to save a screenshot.
3. What to Do If You Forgot the Password
Even if you forgot your MySQL password, you can reset it using a few methods. In this section, we’ll explain password reset procedures for both Linux and Windows. Both methods require administrator privileges, so be sure to perform these steps with administrative access.
3.1 How to Reset the Password on Linux
On Linux, a common approach is to start MySQL in safe mode (with the --skip-grant-tables option) and set a new password.
Steps:
- Stop the MySQL service
Run the following command to stop the MySQL service.
sudo systemctl stop mysqld- Start MySQL in safe mode
In safe mode, user authentication is skipped, allowing you to access MySQL without a password. Run the following command.
sudo mysqld_safe --skip-grant-tables &- Log in to MySQL
After starting in safe mode, log in to MySQL with the following command.
mysql -u root- Set a new password
Run the following SQL command to set a new password.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';*Replace NewPassword123! with an appropriate new password.
- Restart the service
After setting the password, restart the MySQL service in normal mode.
sudo systemctl stop mysqld
sudo systemctl start mysqld- Verify login with the new password
Confirm that you can log in to MySQL using the new password you set.
3.2 How to Reset the Password on Windows
On Windows, you can reset the password by starting MySQL with the --init-file option.
Steps:
- Stop the MySQL service
Open the Services manager and stop the “MySQL service.” - Create an SQL file for reset
Using any text editor, create an SQL file (e.g.,reset_password.sql) with the following content and save it to an appropriate directory.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';*Replace NewPassword123! with the new password you want to use.
- Start MySQL with the
--init-fileoption
Open Command Prompt as Administrator and run the following command.
mysqld --init-file="C:\path o
eset_password.sql"*Replace C:\path o eset_password.sql with the actual path where you saved the SQL file.
- Restart the service
Restart MySQL in normal mode. Either start the service again in the Services manager or run the following command.
net start mysql- Verify login with the new password
Confirm that you can log in to MySQL using the new password you set.
4. Check and Configure Password Policy
MySQL provides a feature called “password policy” to help ensure password security. This allows you to enforce requirements such as minimum complexity and length. Here, we’ll explain how to check the current policy and how to change the settings when needed.
4.1 How to Check the Password Policy
To check the current password policy, you use the validate_password plugin. If this plugin is enabled, MySQL validates passwords based on the configured policy.
Steps:
- Log in to MySQL.
mysql -u root -p- Run the following command to check the current policy settings.
SHOW VARIABLES LIKE 'validate_password%';- The output will show configuration items like the following.
- validate_password.policy: Password policy strength level
- 0 (LOW): Allows only letters and numbers
- 1 (MEDIUM): Requires letters, numbers, and special characters
- 2 (STRONG): Requires letters, numbers, special characters, uppercase letters, and lowercase letters
- validate_password.length: Minimum password length
- validate_password.mixed_case_count: Minimum required count of mixed case characters
- validate_password.number_count: Minimum required count of digits
- validate_password.special_char_count: Minimum required count of special characters
4.2 Change Password Policy Settings
If needed, you can relax or strengthen the password policy. Examples are shown below.
Steps to change the policy settings:
- Log in to MySQL.
mysql -u root -p- Run SQL commands to change the current settings. Example 1: Relax the policy (change to LOW level)
SET GLOBAL validate_password.policy = 0;
SET GLOBAL validate_password.length = 8;Example 2: Strengthen the policy (change to STRONG level)
SET GLOBAL validate_password.policy = 2;
SET GLOBAL validate_password.length = 12;
SET GLOBAL validate_password.special_char_count = 2;- Confirm that the settings were applied.
SHOW VARIABLES LIKE 'validate_password%';Notes:
- To keep the settings after restarting MySQL, it’s recommended to add them to
my.cnformy.ini. - Example:
[mysqld]
validate_password.policy=1
validate_password.length=104.3 Considerations When Changing Settings
- Balance security and usability
Strengthening the password policy improves security, but it can make password management more complex. In environments with many beginners, you should avoid policies that are stricter than necessary. - Operational impact
If existing users do not meet the new policy, errors will occur when they try to update passwords after the change. Check the scope of impact before changing the policy. - Prevent password reuse
In production environments, consider enabling features that prevent reuse of previously used passwords.
5. Troubleshooting
When checking or resetting a MySQL password, you may encounter unexpected errors. In this section, we’ll explain common examples and how to resolve them in detail.
5.1 Common Errors and Their Causes
Error 1: Permission error (Access Denied for User)
- Cause: This occurs when the username or password provided at login is incorrect, or when the user lacks required privileges.
- Solution:
- Verify that you are using the correct username and password.
- Log in as the root user, or ask an administrator to confirm privileges.
- If needed, start MySQL in safe mode (
--skip-grant-tables) and fix privileges.
Error 2: The MySQL service won’t start
- Cause: This can happen if there is an error in the MySQL configuration file (
my.cnformy.ini), or if disk space is insufficient. - Solution:
- Check the MySQL error log file.
- On Linux:
/var/log/mysqld.log - On Windows:
C:\ProgramData\MySQL\MySQL Server X.X\Logs\mysqld.log
- On Linux:
- If there is an error in the configuration file, fix it—especially any newly added settings.
- If disk space is insufficient, delete unnecessary files or expand storage.
- After fixing, restart the service.
bash sudo systemctl restart mysqld
Error 3: Password change doesn’t take effect
- Cause: The privilege tables may not have been reloaded after changing the password.
- Solution:
- After running the password change command, reload privileges with the following command.
sql FLUSH PRIVILEGES; - Restart the MySQL service and try logging in with the new password.
5.2 Recovery Using Safe Mode
If the solutions above do not resolve the issue, you can try recovery using safe mode.
Steps:
- Stop the MySQL service.
sudo systemctl stop mysqld- Start MySQL in safe mode.
sudo mysqld_safe --skip-grant-tables &- While in safe mode, log in to MySQL and fix the affected user’s privileges or password.
- After fixing, exit safe mode and restart MySQL in normal mode.
sudo systemctl restart mysqld5.3 How to Use the Error Log Effectively
The MySQL error log is one of the most important sources of information for troubleshooting. Use the steps below to review it and help resolve issues.
Steps:
- Confirm the location of the error log.
- On Linux (common path):
/var/log/mysqld.log - On Windows:
C:\ProgramData\MySQL\MySQL Server X.X\Logs\mysqld.log
- Display the log file.
tail -n 100 /var/log/mysqld.log*If you want to monitor the latest errors in real time, you can add the -f option.
tail -f /var/log/mysqld.log- Read the log messages and identify the cause of the error.
5.4 What to Do If the Problem Still Isn’t Resolved
- Refer to the official documentation
MySQL’s official documentation contains detailed troubleshooting information by version.
MySQL Official Documentation - Use support forums
Search for similar issues on community forums or Stack Overflow to find solutions. - Consult an expert
If you can’t resolve the problem, consult a system administrator or a MySQL expert.

6. FAQ
While managing or resetting MySQL passwords, you may run into various questions or issues. In this section, we’ll anticipate common questions readers may have and explain each solution clearly.
Q1: What should I do if I can’t find the initial password?
A1:
If you can’t find the initial MySQL password, try the following steps.
- Re-check the log file
- On Linux:
/var/log/mysqld.log - On Windows:
C:\ProgramData\MySQL\MySQL Server X.X\Logs\mysqld.log
The initial password is typically recorded in the log file along with the text “temporary password.”
- Check the installer screen
On Windows, the MySQL installer may display the initial password. Check whether you saved a screenshot right after installation. - Consider reinstalling
If you still can’t find the initial password, uninstalling and reinstalling MySQL may generate a new initial password you can use.
Q2: Why can’t I log in even after resetting the password?
A2:
If you still can’t log in after resetting the password, check the following points:
- Check the username and host
- In MySQL, the combination of username and host is important (e.g.,
'root'@'localhost'). If you use'%', access is allowed from all hosts. - Command to check the user list:
sql SELECT User, Host FROM mysql.user;
- Forgetting to reload the privilege tables
If you don’t reload privileges after resetting the password, the new password won’t take effect. Run the following command.
FLUSH PRIVILEGES;- Restart the MySQL service
After the password reset, restart the MySQL service and then try logging in again.
sudo systemctl restart mysqldQ3: Is it possible to disable the password policy?
A3:
You can disable the password policy, but it increases security risk, so consider it carefully. You can disable the validate_password plugin using the steps below.
- Log in to MySQL.
mysql -u root -p- Run the command to uninstall the plugin.
UNINSTALL PLUGIN validate_password;- Confirm that it has been disabled.
SHOW PLUGINS;Note:
This allows weak passwords, so especially in production environments, strengthen other security measures instead.
Q4: What should I do if I get an error during the password reset?
A4:
Use the following steps as a guide for handling errors during reset.
- Check the error message
- Check the error log to review detailed messages.
- On Linux:
/var/log/mysqld.log - On Windows:
C:\ProgramData\MySQL\MySQL Server X.X\Logs\mysqld.log
- On Linux:
- Fix it in safe mode
If the error continues, start MySQL in safe mode (--skip-grant-tables) and fix the problematic configuration. - Delete and recreate the existing user
If the issue is user-related, deleting and recreating the user can also be effective.
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';Q5: If the password is shared with other administrators, will changing it have an impact?
A5:
If there are multiple administrators, changing the password may have the following impacts.
- Scope of impact
If other administrators’ systems or scripts use the old password, connection errors will occur. - Notify in advance
Before changing the password, notify other administrators and have them update scripts or settings as needed. - Secure sharing after the change
After the change, ensure you have a secure method to share the new password (e.g., an encrypted messaging tool).
7. Summary
Checking and resetting MySQL passwords is one of the essential tasks you can’t avoid when operating a database. In this article, we comprehensively covered everything from how to find the initial password, to resetting a forgotten password, and even password policy configuration and troubleshooting—so that beginners can follow along in practice.
Key Takeaways from This Article
- How to find the initial password
- On Linux, check
/var/log/mysqld.log; on Windows, check themysqld.logfile to retrieve the initial password.
- How to reset a forgotten password
- We covered reset procedures for both Linux and Windows using safe mode and the
--init-fileoption.
- Check and configure password policy
- We explained how to use the
validate_passwordplugin to configure policies that match your environment.
- Troubleshooting
- We introduced concrete responses to common errors such as permission issues and service startup problems.
- FAQ for additional clarification
- We provided answers to common questions and issues that arise during password checks and resets.
Recommendations for Readers
To operate MySQL safely and efficiently, keep the following points in mind.
- Manage passwords thoroughly
Set strong passwords and store them securely. Regularly changing passwords can further strengthen security. - Leverage the error log
When issues occur, get into the habit of checking the error log to identify the cause. - Refer to official documentation
MySQL’s official resources provide the latest, version-specific information. Use them as needed.
Next Steps
By following the steps in this article, you should have gained practical skills for basic MySQL password management and troubleshooting. As next steps, consider the following:
- Further strengthen security
Improve overall database security by configuring firewalls and using SSL connections. - Review backup operations
Establish a regular backup schedule to fully prepare for data loss scenarios.
Manage MySQL properly and achieve smooth, trouble-free operations. We hope this article helps you along the way.


