Techridez
VirtualizationLinuxWindowsNetworking
  • Techridez Knowledge base
  • Techridez guide
  • Tech Scale
    • Measurements
  • Techridez Knowledge Base
  • Bacis
    • Protocol and Port Numbers
  • Windows Customization
    • Capture Wim image from OS
  • Virtualization
    • Proxmox Command Guide
  • Windows Server Guide
    • Transfer FSMO roles
    • FSMO commands
  • DevOps
    • WebDev
      • How to install fail2ban on ubuntu server and create custom jail config.
      • MySQL Bin Files Eating Lots of Disk Space (fix)
      • Install ClamAV antivirus in Ubuntu Server and Client With Cron job
      • 404 hyperlink not working after wordpress migration
      • Apache Virtual Host Script with mysql db.
      • OsTicket
      • How to Backup MySQL Databases Automatically on Ubuntu
      • Cron Job
        • Create cron job for maldet scanning
        • Auto-Restart MySQL When It Crashes During a Brute Force Attack
        • How to change default crontab editor
        • How To Use Cron to Automate Tasks on Ubuntu 18.04
        • How To Use Cron to Automate Tasks on CentOS 8
      • Wordpress Security
      • Open database Error!: could not find driver linux Fix
    • Vagrant
    • Windows Subsystem for Linux
    • How to set static ip on ubuntu server using yaml file.
    • How to install ansible
  • Linux
    • Tools
    • How to install CrowdStrike in Linux
    • How to Install Ossec agent in linux
    • Linux Commands
    • SFTP (CrushFTP)with HA
    • 🗃️Transfer & sync files in a directory to remote node using crontab & rsync
  • Networking
    • Upgrade Cisco9200L firmware to recommended
  • Cyber Security
    • ISC² (International Information System Security Certification Consortium)
Powered by GitBook

©️ Techridez

On this page

Was this helpful?

  1. DevOps
  2. WebDev
  3. Cron Job

Auto-Restart MySQL When It Crashes During a Brute Force Attack

During a brute force attempt, running on a low-memory virtual private server (VPS) can cause MySQL to crash and render your websites unusable.

Especially WordPress sites are targeted because they run on PHP and MySQL and are apparently powering over 28% of the internet’s content management systems.

The most fruitful solution is to permanently increase your VPS’s memory, but I can understand that administrators refuse to pay for resources that are otherwise never utilized during normal operation. To keep things up and running automatically after a crash, I use a simple cronjob to check and restart MySQL if it is down.

Load the crontab editor in the terminal with crontab -e and add the following line:

* * * * * service mysql status > /dev/null || service mysql start

This checks if MySQL is running every minute and redirects stdout to null.

Starting the service will not output anything unless something goes wrong, so there is no need to add the null redirect on the last command. The double pipe || means OR and will execute the second command only if the first command fails. In other words: if MySQL’s status returns an exit code greater than zero (first command), start MySQL (second command).

This is unlike the double ampersand && which is similar to saying, “Run the first command, and, only if the first command was successful, run the second command.”

If checking every single minute is too frequent, a five-minute interval will do just as fine for smaller websites:

*/5 * * * * service mysql status > /dev/null || service mysql start

Got it from

https://medium.com/@mhagemann/how-to-auto-restart-mysql-when-it-crashes-during-a-brute-force-attack-d7a03b726b7e

Thanks for the article.

PreviousCreate cron job for maldet scanningNextHow to change default crontab editor

Last updated 4 years ago

Was this helpful?