mysql新增普通用户并授权

1、创建用户

create user '[用户名称]'@'%' identified by '[用户密码]';

密码8位以上,包括:大写字母、小写字母、数字、特殊字符
%:匹配所有主机,该地方还可以设置成‘localhost’,代表只能本地访问,例如root账户默认为‘localhost‘

2、 用户授权数据库

1)指定数据库 读写等权限

grant select,insert,update,delete,create on [数据库名称].* to [用户名称];

2)所有库 读写等权限
[数据库名称] 换成 * 代表整个数据库

grant select,insert,update,delete,create on *.* to [用户名称];

3)指定库 所有操作权限

grant all privileges on  [数据库名称].* to [用户名称];

4)所有库 所有操作权限

grant all privileges on *.* to [用户名称];

3、立即启用修改

flush  privileges ;

4、取消用户所有数据库(表)的所有权限

revoke all on *.* from [用户名称];

5、删除用户

delete from mysql.user where user= [用户名称];

6、删除数据库

drop database [schema名称|数据库名称];

样例:

create user 'test'@'%' identified by 'test@abc'; -- 创建用户
grant select,insert,update,delete,create on *.* to test; --用户授权数据库
flush privileges;--立即启用修改

猜你喜欢

转载自blog.csdn.net/weixin_41003771/article/details/114536758