sql语句---用户权限设置

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/g_optimistic/article/details/88566179

目录

1、创建用户(基于mysql.user表)

2、授权

(1)给数据库中的表赋予权限

(2)查询权限


用户授权

用户名 user
主机 host
密码 password

1、创建用户(基于mysql.user表)

创建用户
CREATE USER 用户名@主机;
创建用户并添加密码
CREATE USER 用户名@主机 IDENTIFIED BY "密码";
允许用户远程登录
create user laobian1@'%' iidentified by "1234";

//允许10.10.65.0~10.10.65.255以laobian1登录mysql:
create user laobian@'10.10.65.%' identified by "1234";

允许10.10.65.250~10.10.65.255以laobian2登录mysql:
create laobian2@'10.10.65.25%' identified by "1234";
允许10.10.65.20~10.10.65.29以laobian3登录mysql:
create laobian3@'10.10.65.2_' identified by "1234";
删除用户
drop user [email protected];

2、授权

常规权限(增删改查)

查询权限 select
插入权限 insert
更新权限 update
删除权限 delete
创建权限 create

(1)给数据库中的表赋予权限

GRANT COMMAND ON DATABASE.TABLE TO USER@HOST
grant select,insert,delete,update,create on laobian2.* to 'laobian2'@'10.10.65.%';
grant insert on laobian2.person2 to 'laobian2'@'10.10.65.%';
grant select on laobian.person to laobian@localhost;
给laobian数据库的peron表的查询授权给以localhost登录的laobian用户
grant update on laobian.person to laobian@localhost;
grant select(id,name) on bian.person to laobian@localhost;
将bian数据库的person表的select查询权限授权给以localhost登录的laobian用户

(2)查询权限

SHOW GRAMTS FOT USER@HOST;
show grants for [email protected];

猜你喜欢

转载自blog.csdn.net/g_optimistic/article/details/88566179