1、设置MySQL用户密码。使用create user命令创建新用户,同时使用identified by指定用户密码。例子:create user 'bob'@'%' identified by 'mysql';
2、设置MySQL用户密码的加密协议。用户密码加密方式存储在mysql数据库user表的plugin字段中,有两种方式分别是mysql_native_password和caching_sha2_password,默认采用caching_sha2_password加密协议。例子:alter user 'bob'@'%' identified with mysql_native_password by 'mysql';
3、设置MySQL用户密码的过期时间。用户密码过期时间存储在mysql数据库user表的password_expired,password_lifetime字段中。可以设置成从不过期或指定过期时间或直接强制过期或采用默认过期策略。例子:alter user 'bob'@'%' password expire interval 100 day;
4、锁定MySQL用户账号。用户密码过期时间存储在mysql数据库user表的account_locked字段中。使用account lock锁定,account unlock解锁。例子:alter user 'bob'@'%' account lock;
5、设置MySQL用户角色。通过给角色分配一组权限,我们可以直接给某个用户设置成这个角色之后,那么这个用户就直接拥有这一组的权限,这样更方便地管理具有相同权限的一组用户。使用create role命令来创建角色。例子:create role app_role1;
6、设置MySQL用户角色权限。需要先为角色授权,再给用户授权。授权命令使用grant命令。例子:grant select on test.* to app_role1 ; grant app_role1 to 'bob'@'localhost';
7、总结:1.设置Mysql用户密码。2.设置MySQL用户密码的加密协议。3.设置MySQL用户密码的过期时间。4.锁定MySQL用户账号。5.设置MySQL用户角色。6.设置MySQL用户角色权限。