Mysql8创建视图,并赋予相应用户查看权限

创建视图不用多说,SQL写好之后在Navicat工具点击新建视图粘贴进去就行了

在 Mysql5 版本中,我们可以直接一句SQL完成创建用户和授权的过程

grant select on db.table to name@'%' identified by 'password';

但是在 Mysql8 版本中,创建用户和赋予权限分开了,这样使用会报语法错误

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

因此我们要分开操作

首先别忘记把 root 的 host 改成 %

update user set host=’%’ where user=‘root’;

不然会报错

You are not allowed to create a user with GRANT

第一步,创建用户

create USER 'name'@'%' identified  by 'password';

第二步,赋予权限

GRANT SELECT,SHOW VIEW ON 'db'.'view' TO 'name'@'%'

第三步,刷新权限

flush privileges;

然后就大功告成,用创建的用户登录就行了

猜你喜欢

转载自blog.csdn.net/weixin_42559574/article/details/126727001
今日推荐