目录

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 laobian@10.10.65.250;

 

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 laobian@10.10.65.250;

更多推荐

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