Many people encounter the 1045 error when using Navicat to connect to MySQL databases. The main reason is that the username or password you entered is incorrect and access is denied. If you do not want to reinstall, you will need to retrieve or reset your password.


Navicat for MySQL 1045  error


Problem description:

1045-Access denied for user 'root'@'localhost'(using password: YES)


Root cause analysis:

When logging into the MySQL database and encountering Error 1045, it indicates that the username or password you entered is incorrect and access has been denied. The simplest solution is to uninstall and reinstall the MySQL database, but the downside is that the information in the previous database will be lost. If you don't want to reinstall, then you need to retrieve or reset your password. There should be multiple solutions, and here I recommend using a simple method that is suitable for the Windows platform.



Solution:

1. Stop service: Stop MySQL service;

Method 1: Use the DOS command net stop mysql; The MySQL service must be installed in this way, otherwise the service name will be invalid.

Method 2: Go to [Control Panel] -->[Management Tools] -->[Services], find the MySQL service, and click on the stop button on the left.



2. Skip verification: Modify the my.ini configuration file in the MySQL installation directory to skip permission checks during login;

Enter the installation path of MySQL. Taking the default installation path as an example, C:\Program Files\MySQL\MySQL Server 5.1\, Find the my.ini configuration file, which records the general parameters of MySQL. Every time the service is started, this file will be loaded first. Add skip0guarnt_tables to the last line of the my.ini configuration file. This statement can ignore login checks.



3. Change password: Start the MySQL service, log in to MySQL, and you will be prompted to enter your password. Enter any password and press enter to enter MySQL. Then modify the password of the root user through SQL statements;

Start the MySQL service, enter the DOS environment, enter mysql - u root - p to log in to MySQL. If adding environment variables is not checked during installation, you need to first use the cd command to enter the MySQL installation directory. At this time, you will be prompted to enter the password. Enter any password and press enter to enter MySQL. The 'mysql>' control character will appear, indicating that you have successfully logged in to MySQL.

mysql> USEmysql , Switch the database to the MySQL database.

MySQL>Update user SET password=PASSWORD ('newpswd ') WHERE user='root' Change password.

The password function is an internal MySQL function, where newpswd is the modified new password.


4. Restart the service: Remove or add # comments to skip permission statements added in the my.ini file. Restart the service and log in with the modified password.

Remove or add # comments to skip permission statements added in the my.ini file. Restart the service and log in with the modified password.