MYSQL8用户建立及权限操做

MYSQL8建立、删除用户和受权、消权操做

 

上网找过资料说要进入mysql数据库在进行这些操做,我试了发现不进数据库和进入mysql数据库效果都同样mysql

 

网上有的直接建立并赋权,像酱紫的:sql

grant all privileges *.* to '要建立的用户'@'localhost' identified by '自定义密码';数据库

我在mysql8试了不行(8版本如下还没试过),要先建立用户再进行赋权,不能同时进行ide

 

建立用户ip

create user 'test1'@'localhost' identified by '‘密码';it

flush privileges;刷新权限io

 

其中localhost指本地才可链接test

能够将其换成%指任意ip都能链接date

也能够指定ip链接select

 

修改密码

Alter user 'test1'@'localhost' identified by '新密码';

flush privileges;

 

受权

grant all privileges on *.* to 'test1'@'localhost' with grant option;

 

with gran option表示该用户可给其它用户赋予权限,但不可能超过该用户已有的权限

好比a用户有select,insert权限,也可给其它用户赋权,但它不可能给其它用户赋delete权限,除了select,insert之外的都不能

这句话可加可不加,视状况而定。

 

all privileges 可换成select,update,insert,delete,drop,create等操做

如:grant select,insert,update,delete on *.* to 'test1'@'localhost';

 

第一个*表示通配数据库,可指定新建用户只可操做的数据库

如:grant all privileges on 数据库.* to 'test1'@'localhost';

 

第二个*表示通配表,可指定新建用户只可操做的数据库下的某个表

如:grant all privileges on 数据库.指定表名 to 'test1'@'localhost';

 

 

查看用户受权信息

show grants for 'test1'@'localhost';

 

 

撤销权限

revoke all privileges on *.* from 'test1'@'localhost';

用户有什么权限就撤什么权限

 

删除用户

drop user 'test1'@'localhost';

相关文章
相关标签/搜索