stronger-xsw

假如是mysql8版本的话,使用

grant all privileges *.* to \'用户\'@\'localhost\' identified by \'自定义密码\';
会报错,因为要先创建用户再进行赋权,不能同时进行

创建用户

create user \'用户名\'@\'localhost\' identified by \'密码\';
flush privileges;刷新权限
其中localhost指本地才可连接

可以将其换成%指任意ip都能连接

也可以指定ip连接(192.168.110.131)
或者某个网段(192.168.110.%)

修改密码

Alter user \'用户\'@\'localhost\' identified by \'新密码\';

flush privileges;

授权

grant all privileges on *.* to \'用户\'@\'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 \'用户\'@\'localhost\';

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

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

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

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

查看用户授权

show grants for \'用户\'@\'localhost\';

撤销权限

revoke all privileges on *.* from \'用户\'@\'localhost\';

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

删除用户

drop user \'用户\'@\'localhost\';

分类:

技术点:

相关文章:

  • 2021-12-18
  • 2021-10-15
  • 2021-11-03
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2021-12-13
  • 2022-12-23
  • 2021-09-16
  • 2021-05-18
  • 2022-02-23
  • 2022-12-23
相关资源
相似解决方案