MySQL8 设置权限报错:ERROR 1396 (HY000)、ERROR 1064 (42000)、ERROR 1410 (42000)

 问题:

ERROR 1396 (HY000): Operation ALTER USER failed for '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 'identified by 'MyAdmin123!@#'' at line 1

ERROR 1410 (42000): You are not allowed to create a user with GRANT 

D:\mysql-8.0.34-winx64\bin>mysql -uroot -p
Enter password: *************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed
mysql> alter user 'root'@'%' identified by  'MyAdmin123!@#';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
mysql> grant all on *.* to root@'%' identified by 'MyAdmin123!@#';
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 'identified by 'MyAdmin123!@#'' at line 1

解决:

mysql> use mysql;
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql>

你可能感兴趣的:(adb)