Mysql出现:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

problem:

C:\Users\ASDS>mysql -uroot -p

Enter password: **********

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

 

The reason for this situation:

  1. Incorrect password
  2. Mysql service is not open

 

Solution:

Enter the mysql installation directory: find my.ini

Win10 system is in C: \ ProgramData \ under MySQL \ MySQL Server 5.7 directory

Editing my.ini add a line: skip-grant-tables

Figure:

 

Enter the mysql database

mysql -uroot -p

Password do not fill, just press Enter

Access to the database

use mysql # set to enter the mysql database

desc user # view the user table structure

 

| plugin                 | char(64)                          | NO   |     | mysql_native_password |       |

| authentication_string  | text                              | YES  |     | NULL                  |       |

| password_expired       | enum('N','Y')                     | NO   |     | N                     |       |

| password_last_changed  | timestamp                         | YES  |     | NULL                  |       |

| password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |

| account_locked         | enum('N','Y')                     | NO   |     | N                     |       |

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

45 rows in set (0.01 sec)

 

mysql> select user,authentication_string where user="root";

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where user="root"' at line 1

mysql> select user,authentication_string from user where user="root";

+------+-------------------------------------------+

| user | authentication_string                     |

+------+-------------------------------------------+

| root | *33E5325E7E3283C80E0C495434954FD74919C12D |

+------+-------------------------------------------+

1 row in set (0.01 sec)

# Change the root user's password:

mysql> update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';

Query OK, 1 row affected, 1 warning (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 1

 

mysql> select user,authentication_string from user where user="root";

+------+-------------------------------------------+

| user | authentication_string                     |

+------+-------------------------------------------+

| root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

+------+-------------------------------------------+

1 row in set (0.00 sec)

#Successfully modified!

Back my.ini file, just add the code to delete, save

Restart the mysql service, my mysql version is 5.7, win10 system

Run as Administrator command line window close or open the mysql service:

net start service name  

For example:

net stop mysql57

net start mysql57

Mysql service starts successfully, you can use the user to enter a user password just set the mysql database

Guess you like

Origin blog.csdn.net/weixin_41808843/article/details/89502011