如何在 MySQL 8.0 中授予 root 用户所有权限
尝试过
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
获取
ERROR 1064 (42000):您的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本,以便在第 1 行的IDENTIFIED BY 'root' WITH GRANT OPTION"附近使用正确的语法.
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 'root' WITH GRANT OPTION' at line 1.
注意:在以前的版本中尝试时也是如此.
Note: The same is working when tried in previous versions.
也试过了
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
获取
ERROR 1410 (42000):您不能使用 GRANT 创建用户
ERROR 1410 (42000): You are not allowed to create a user with GRANT
MySQL (8.0.11.0) 用户名/密码是 root/root.
MySQL (8.0.11.0) username/password is root/root.
推荐答案
从 MySQL 8 开始,您不再可以(隐式地)使用 GRANT
命令创建用户.使用 CREATE USER 代替,后跟 GRANT 声明:
Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT
command. Use CREATE USER instead, followed by the GRANT statement:
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
注意有关WITH GRANT OPTION
的安全风险,请参阅:
Caution about the security risks about WITH GRANT OPTION
, see:
- 授予所有数据库权限
相关文章