MySQL8.x-用户管理

82 阅读1分钟

所谓"白名单"

都是谁能访问MySQL?应用程序、管理员、MySQL备份、监控这些会访问。

白名单就是控制哪些"人"能访问MySQL服务。

白名单设置越精细越好,最起码能防止一些攻击。

用户管理

注意,不同的MySQL版本,用户管理的命令也略有不同,当然那,也包含其它的命令,都会多多少少的有点区别,这点你在做相关操作时要额外注意,你的MySQL版本。

desc mysql.user;

	    用户  白名单    密文密码            密码加密的方式(插件)
select user,host,authentication_string,plugin from mysql.user;
-- 创建一个支持远程连接的用户,但此时该用户只能登录到MySQL,但啥权限都没有
create user zhangkai@'%' identified by "123";

create user zhangkai@'%' identified with mysql_native_password by "123";


-- 修改密码插件时要同时修改其密码,也就是让它以修改后的插件从新加下密
alter user zhangkai@'%' identified with mysql_native_password by "123";
drop user zhangkai@'%';
alter user root@'localhost' identified with mysql_native_password by "123";

用户资源管理

普通账号密码忘记找回

root账号密码忘记找回

关闭数据库



mysqld_safe --skip_grant-tables --skip-networking & 
-- 解释下
-- --skip_grant-tables 跳过授权表登录 
-- --skip-networking   禁用远程登录,只能本地登录

flush privileges;
alter user root@'localhost' identified with mysql_native_password by "123";
shutdown;