MySQL限制登陆失败次数配置

发布于:2024-06-11 ⋅ 阅读:(35) ⋅ 点赞:(0)

目录

 

一、限制登陆策略

1、Windows 

2、Linux


一、限制登陆策略

1、Windows 

1)安装插件

登录MySQL数据库

mysql -u root -p 

执行命令安装插件

#限制登陆失败次数插件
install plugin CONNECTION_CONTROL soname 'connection_control.dll';
 
install plugin CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS soname 'connection_control.dll';

2)设置策略

 1.临时

在命令行执行设置命令,临时,重启数据库后会重置

注:connection_control_max_connection_delay为限制重试最能到时间,这个一般不设置,如果要设置,按最小时间的格式加进去就行。

connection-control-failed-connections-threshold=5   
connection-control-min-connection-delay=300000    

#登陆失败次数限制
SET GLOBAL connection_control_failed_connections_threshold = 5;

#限制重试最小时间,单位为毫秒,注意换算,这为5分钟
SET GLOBAL connection_control_min_connection_delay = 300000;
2.永久

 在MYSQL配置文件my.ini中的 [mysqld] 下添加。

注:connection_control_max_connection_delay为限制重试最能到时间,这个一般不设置,如果要设置,按最小时间的格式加进去就行。

#插件,登陆失败处理
plugin-load-add = validate_password.so

plugin-load-add = connection_control.so


#登陆失败次数限制
connection_control_failed_connections_threshold=5

#限制重试最小时间,单位为毫秒,注意换算,这为5分钟
connection_control_min_connection_delay=300000 

配置好后重启数据库

net restart mysql

3)查看

登录数据库查看是否生效

mysql -u root -p 
show variables like '%connection_control%';

2、Linux

1)安装插件

登录MySQL数据库

mysql -u root -p 

登录后执行命令安装插件

#限制登陆失败次数插件
install plugin CONNECTION_CONTROL soname 'connection_control.so';

install plugin CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS soname 'connection_control.so';

2)设置策略

1.临时

在命令行执行设置命令,临时,重启数据库后会重置

 注:connection_control_max_connection_delay为限制重试最能到时间,这个一般不设置,如果要设置,按设置最小时间的格式加进去就行。

connection-control-failed-connections-threshold=5   
connection-control-min-connection-delay=300000    

#登陆失败次数限制
SET GLOBAL connection_control_failed_connections_threshold = 5;

#限制重试最小时间,单位为毫秒,注意换算,这为5分钟
SET GLOBAL connection_control_min_connection_delay = 300000;
2.永久

 在MYSQL配置文件my.cnf中的 [mysqld] 下添加。

注:connection_control_max_connection_delay为限制重试最能到时间,这个一般不设置,如果要设置,按设置最小时间的格式加进去就行。

#插件,登陆失败处理
plugin-load-add = validate_password.so

plugin-load-add = connection_control.so



#登陆失败次数限制
connection_control_failed_connections_threshold=5

#限制重试最小时间,单位为毫秒,注意换算,这为5分钟
connection_control_min_connection_delay=300000 

配置好后重启数据库

systemctl restart mysqld

3)查看

 登录数据库查看是否生效

mysql -u root -p 
show variables like '%connection_control%';