MySQL 5.7 以后提供了Connection-Control插件用來控制客戶端在登錄操作連續失敗一定次數后的響應的延遲。 該插件可有效的防止客戶端暴力登錄的風險(攻擊)。該插件包含以下兩個組件: connection_control:控制失敗次數以及延遲時間 connection_control_failed_login_attempts:將登錄失敗的操作記錄至information_schema表 my.cnf添加以下配置 [mysqld] plugin-load-add = connection_control.so connection-control = FORCE connection-control-failed-login-attempts = FORCE connection_control_min_connection_delay = 1000 connection_control_max_connection_delay = 86400 connection_control_failed_connections_threshold = 5 執行安裝命令,使用root賬戶登錄 mysql> install plugin connection_control soname "connection_control.so"; mysql> install plugin connection_control_failed_login_attempts soname "connection_control.so"; 驗證插件安裝狀態 mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'connection%'; +------------------------------------------+---------------+ | plugin_name | plugin_status | +------------------------------------------+---------------+ | CONNECTION_CONTROL | ACTIVE | | CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS | ACTIVE | +------------------------------------------+---------------+ 2 rows in set (0.00 sec) 查看用戶登錄失敗次數,當用戶登錄成功則刪除記錄 mysql> select * from information_schema.connection_control_failed_login_attempts; 連接控制的使用次數 mysql> show global status like 'connection_control_delay_generated'; 超過失敗次數如果想要馬上登錄,需要設置一下即可。 mysql> set global connection_control_failed_connections_threshold=0; 成功后別忘了改回來 mysql> set global connection_control_failed_connections_threshold=5;