Web Hosting & VPS Tips

Unleash Your Server Potential with Expert Insights

Hosting provided by: Cloudways
Free to Try! Up to 40% Off!

Category: VPS Setup

Guard MySQL against attacks on your Ubuntu VPS with Fail2ban—install with
apt install fail2ban -y
then create /etc/fail2ban/jail d/mysql conf via
nano /etc/fail2ban/jail.d/mysql.conf
Add:
[mysql]\nenabled = true\nport = 3306\nfilter = mysqld-auth\nlogpath = /var/log/mysql/error.log\nmaxretry = 5\nbantime = 86400
Copy the filter with
cp /etc/fail2ban/filter.d/mysqld-auth.conf /etc/fail2ban/filter.d/mysqld-auth.local
and restart with
systemctl restart fail2ban
Open MySQL port with
ufw allow 3306
and check bans with
fail2ban-client status mysql
On Vultr this bans IPs for 24 hours (86400s) securing phpMyAdmin and ensuring database uptime

Back to All Tips