MySQL添加用户并授权

执行前要确认,授权给这个用户的数据库已经被创建好

create database 库名 character set utf8mb4;

接下来,可以采用直接授权的方式,能够同时创建用户以及授权(仅适用于MySQL8以下版本)

--MySql5.7
grant select,insert,delete,update,create on 库名.* to '用户名'@'%' identified by '密码';

8.0以上版本将创建账户和赋予权限分开了

#创建账户
create user '用户名'@'%' identified by '密码';

#赋予权限
grant select,insert,delete,update,create on 库名.* to '用户名'@'%';
posted @ 2023-09-02 22:28  洗洗早睡啦  阅读(48)  评论(0编辑  收藏  举报