ERROR 1062 (23000): Duplicate entry ‘%-root‘ for key ‘user.PRIMARY‘

1. Error reporting

MySQL execution command:

UPDATE user SET host = '%' WHERE user = 'root';

Error:

ERROR 1062 (23000): Duplicate entry '%-root' for key 'user.PRIMARY'

mysql> UPDATE user SET host = '%' WHERE user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'user.PRIMARY'

Two, the reason 

view all users

select host, user from user;

It is found that there are two root users, and we delete the piece of data whose host is host.

 

mysql> DELETE FROM user WHERE user = 'root' AND host = 'host';
Query OK, 1 row affected (0.01 sec)

 update again

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

View user data again

mysql> select host, user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

At this point HOST has become %

Last use changes to take effect

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

 

Guess you like

Origin blog.csdn.net/qq_39208536/article/details/132688433