您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql8创建、删除用户及授权、消权操作的方法

2024/3/9 2:25:37发布20次查看
1、登录mysqlmysql -uroot -p
2、先查询都有哪些用户select host,user from mysql.user;
请勿对黄色箭头进行操作,它是mysql系统自带的;而红色箭头则表示主管理员。蓝色箭头是子用户,这个是我以前匹配的,现在删掉,我们重新来。
3、删掉用户:drop user '用户名'@'主机名';drop user 'wyy'@'192.168.0.105';
4、创建用户create user '用户名'@'允许那个主机链接' identified by '密码';create user 'wyy'@'192.168.0.105' identified by 'wyy18222';只允许192.168.0.105的主机链接
备注:
mysql8.0 默认采用 caching-sha2-password 加密,有可能旧的客户端不支持,可改为 mysql_native_password;
create user 'test'@'%' identified with mysql_native_password by '密码';
百分号%;表示任何ip地址都可以链接
create user ‘wyy’@‘192.168.0.105’ identified by ‘wyy18222’;这个是只能192.168.0.105的链接。
5、修改密码alter user '用户名'@'主机名' identified by '新密码';alter user 'wyy'@'192.168.0.105' identified by '123';
6、授权给用户授权所有权限
grant all privileges on *.* to '用户名'@'主机名' with grant option;grant all privileges on *.* to 'wyy'@'192.168.0.105' with grant option;
grant:授权、授予
privileges:权限,特权
第一个星号:表示所有数据库
第二个星号:表示所有表
the with grant option indicates that the user can grant permissions to other users, but not beyond the permissions granted to themselves.。这个不加也行。
例如:如果wyy只有select、update权限,没有insert、delete权限,给另一个用户授权时,只能授予它select、update权限,不能授予insert、delete权限。
给用户授权个别权限
all privileges 可换成 select,update,insert,delete,drop,create 等操作
grant select,insert,update,delete on *.* to '用户名'@'主机名';
给用户授权指定权限
给用户授予指定的数据库权限
grant all privileges on 数据库 . * to 'wyy'@'192.168.0.105';grant all privileges on xrs . * to 'wyy'@'192.168.0.105';将数据库名为xrs的所有权限赋予wyy
给用户授予指定的表权限
grant all privileges on 数据库 . 指定表名 to 'wyy'@'192.168.0.105';将某个数据库下的某个表的权限赋予wyy
注意:
网上有的直接创建并赋权:
grant all privileges * . * to ‘要创建的用户’@‘localhost’ identified by ‘自定义密码’;
我在mysql8试了不行(8版本以下还没试过),要先创建用户再进行赋权,不能同时进行
7、刷新权限flush privileges;
新设置用户或更改密码后需用flush privileges刷新mysql的系统权限相关表,
否则会出现拒绝访问
还有一种方法,就是重新启动mysql服务器,来使新设置生效。­
8、查看用户授权show grants for 'wyy'@'192.168.0.105';
9、撤销用户授权(销权)revoke all privileges on *.* from 'wyy'@'192.168.0.105';
用户有什么权限就撤什么权限
补充:mysql8.0 创建用户和授权用户遇到的坑创建用户:
create user username@localhost identified with mysql_native_password by 'password';(with mysql_native_password 如果没有这个,navicat将无法登陆提示:2059 - authentication plugin...错误,因为navicat不支持最新数据库默认的加密方式);
授权用户:
grantall privilegeson databasename.*to username@'ip';(注意这点跟以往数据库都不一样,无需后面跟着identified by 'password';否则将提示error 1064 (42000): you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'identified by 'password'' at line 5)
以上就是mysql8创建、删除用户及授权、消权操作的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product