Resolution of MySql error code 1045 under Windows

  • 2020-06-15 10:24:29
  • OfStack

 The error code  1045
Access denied for user 'root'@'localhost' (using password:YES)

The solution is to reset the root user password. On the Windows platform, the steps are as follows:
1. Log in to the system as the system administrator;
2. If the MySQL server is running, stop it.
If you are running as an Windows service, go to the Service Manager: Start menu - > Control panel - > Management tool - > service
If the server is not running as a service, you may need to use the task manager to force it to stop.
3. Create a text file and place the following command on a single line:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');


Save the file by any name. In this case, the file is C:\ mysql-ES23en.txt.
4, enter DOS command prompt: Start menu - > Run - > cmd
Suppose you have installed MySQL to C:\mysql. If you have Installed MySQL in another location, adjust the following commands accordingly.
At the DOS command prompt, execute the command:

C:\> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt

At server startup, change the root password by executing the contents of the file named by the "-- ES40en-ES41en" option (role: reads the SQL command from the specified file at startup). When the server starts successfully, C:\ mysql-ES45en.txt should be deleted.
5. Stop the MySQL server and restart it in normal mode. If the server is running as a service, it should be started from the Windows service window. If you start the server manually, you can use the command as you would in a normal situation.


Additional methods:

Method 1:


# /etc/init.d/mysql stop 
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
# mysql -u root mysql 
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# /etc/init.d/mysql restart 
# mysql -uroot -p 
Enter password: < Enter the new password newpassword> 
mysql> 

Method 2:

Directly using the/etc mysql/debian cnf file [client] section provides the user name and password:


# mysql -udebian-sys-maint -p 
Enter password: < The input [client] Section of the password > 
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# mysql -uroot -p 
Enter password: < Enter the new password newpassword> 
mysql> 

Another way
Windows:

1. Administrator logs into the system to stop THE mysql service or end the ES75en-ES76en process
2. Enter the command line and go to the installation directory of mysql. Suppose the installation directory is d:\mysql\, CMD enter the command line
3. Run d:\mysql\bin\ ES86en-ES87en -- skip-ES89en-ES90en to start mysql and turn off the permission check
4. Run d:\mysql\bin\ mysqladmin-ES98en flush-ES101en "newpassword" to reset the root password
Restart the mysql service


Related articles: