Mysql Error 1045
Contents
I recently learned databases by myself and encountered some errors when using MySQL under the Win7 system. I made a record for future reference.
The community version of MySQL 5.5.56 was downloaded from the MySQL official website and installed normally. When I enter mysql -u root -p on the command line, an error message appears and I cannot connect to the database.
C:\Windows\system32> mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
The solutions found online are as follows:
- Edit the mysql configuration file
my.iniand add it under the entry[mysqld]
skip-grant-tables
- Save
my.iniand exit and then restart mysql.
Enter net stop mysql on the command line to stop the MySQL service;
Enter net start mysql on the command line to restart the MySQL service;
- Reset password:
Now enter
mysql -u root -pon the command line to log in without a password. Whenpassword:appears, just press Enter to enter.ERROR 1045 (28000)will not appear.
- Enter the mysql database: enter
use mysql, and the prompt messageDatabase changedwill appear.
mysql> use mysql;
Database changed
- Set a new password for the root user: enter
update user set password=password("new password") where user="root";
mysql> update user set password=password(“new password”) where user=“root”; Query OK, 1 rows affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0
- Refresh the database: Enter
flush privileges;
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
- Exit mysql: enter
quit
mysql> quit Bye
- Re-modify the configuration file
my.ini, delete the line of codeskip-grant-tablesthat was just added, save and exit, and then restart the mysql service.