MySQL8+使用 grant identified by 时 error 1064 near 'identified by '密码'' at line 1

2023-10-11 14:29:02 浏览数 (2)

报错截图:

解决:

5.x版本直接一句话就可以创建用户并赋予,而8.x后,需要先创建用户,再GRANT;

代码语言:javascript复制
5.x:
GRANT ALL PRIVILEGES ON *.* TO 'remote'@'%' IDENTIFIED BY 'Rookie123' WITH GRANT OPTION;

8.x:
创建账户:
create user '用户名'@'访问主机' identified by '密码';
赋予权限:
grant 权限列表 on 数据库 to '用户名'@'访问主机' ;(修改权限时在后面加with grant option)

eg:
create user 'remote'@'%' identified by 'Rookie123';
GRANT ALL PRIVILEGES ON *.* TO 'remote'@'%';
GRANT ALL PRIVILEGES ON *.* TO 'remote'@'%' IDENTIFIED BY 'Rookie123' WITH GRANT OPTION;

# 不推荐,字段可能有所改变
use mysql;
update user set host = '%' where user = 'remote';

0 人点赞