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

本文介绍了如何在MariaDB 10.4.21及以上版本中启用并配置密码复杂度和过期策略。通过SQL语句和配置文件设置,可以实现密码最小长度、特殊字符、字母和数字的要求,并设定密码过期时间和最大错误登录次数。同时,展示了查询用户密码过期信息的方法,帮助管理员有效管理数据库安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值