Solution of root account prompt mysql ERROR 1045 of 28000: Access denied for use when logging in after newly installing MySql

  • 2021-07-06 11:56:28
  • OfStack

After the new MySQL is installed, it is implemented for the first time mysql -uroot -p You will find that the root password is not empty. To reset the root password, please refer to the following steps.

Edit the mysql configuration file my. ini (rename my. ini if it is my_default. ini) and add under the entry [mysqld]


 skip-grant-tables

Restart mysql after saving and exiting, and click "Start"- > "Run" (shortcut key Win+R).

1. Stop: Enter net stop mysql

2. Start: Enter net start mysql

At this time, you can log in without password by entering mysql-u root-p in cmd. When password: appears, you can enter directly without ERROR 1045 (28000), but many operations will be restricted because we can't grant (without permission). Follow the following process:

1. Access the mysql database:


mysql> use mysql;
Database changed

2. Set a new password for root users, and enter the blue part yourself:


mysql> update user setauthentication_string=password(" New password ") where user="root";
Query OK, 1 rows affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

3. Refresh the database


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4. Exit mysql:


mysql> quit
Bye

After the change, modify the file my. ini, delete the line "skip-grant-tables" that we just added, save and exit, and then restart mysql.

You will be prompted when you log in again


ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo re executing this statement.

Just enter set password=password('新密码'); You can


Related articles: