MariaDB开启密码复杂度审计和密码过期——筑梦之路

MariaDB 开启密码复杂度和密码过期策略

MariaDB 版本:10.4.21及以上

sql语句设置方式(重启失效)
#安装启用
INSTALL SONAME 'simple_password_check';
#检查验证
show variables like '%password%';

set global simple_password_check_minimal_length=8;

set global simple_password_check_other_characters=1;

set global simple_password_check_letters_same_case=1;

set global simple_password_check_digits=1;

配置文件设置方式
vim /etc/my.cnf.d/server.cnf  
#配置文件添加如下参数
[mysqld]
#加载密码复杂度审计插件
plugin-load=simple_password_check.so
#密码长度,默认8位
simple_password_check_minimal_length=8
#特殊符号,1代表至少1位
simple_password_check_other_characters=1
#字母数,1代表至少1位
simple_password_check_letters_same_case=1
#数字数,1代表至少1位
simple_password_check_digits=1
#默认密码过期时间 单位天 每过180天就要修改密码
default_password_lifetime=180
#最大错误登录次数
max_password_errors=5



#sql语句设置用户密码过期时间
##密码有效期设置 sql语句
create user 'test'@'localhosts' identified by '123QWe!@#'  password expire interval 30 day;     #30天过期
create user 'test'@'localhost' password expire never;                                           #永不过期
alter user 'test'@'localhost' password expire interval 120 DAY;                                 #修改为120天过期
alter user 'test'@'localhost' password expire never;                                            #修改为永不过期

#查询
WITH password_expiration_info AS (
  SELECT User, Host,
  IF(
   IFNULL(JSON_EXTRACT(Priv, '$.password_lifetime'), -1) = -1,
   @@global.default_password_lifetime,
   JSON_EXTRACT(Priv, '$.password_lifetime')
  ) AS password_lifetime,
  JSON_EXTRACT(Priv, '$.password_last_changed') AS password_last_changed
  FROM mysql.global_priv
)
SELECT pei.User, pei.Host,
  pei.password_lifetime,
  FROM_UNIXTIME(pei.password_last_changed) AS password_last_changed_datetime,
  FROM_UNIXTIME(
   pei.password_last_changed +
   (pei.password_lifetime * 60 * 60 * 24)
  ) AS password_expiration_datetime
  FROM password_expiration_info pei
  WHERE pei.password_lifetime != 0
   AND pei.password_last_changed IS NOT NULL
UNION
SELECT pei.User, pei.Host,
  pei.password_lifetime,
  FROM_UNIXTIME(pei.password_last_changed) AS password_last_changed_datetime,
  0 AS password_expiration_datetime
  FROM password_expiration_info pei
  WHERE pei.password_lifetime = 0
   OR pei.password_last_changed IS NULL;

你可能感兴趣的:(数据库技术,linux系统运维,mariadb,sql,数据库)