How to Automatically Restart MYSQL When it Crashes in Aapanel

Posted on

Hi guys, often happen, that whenever MySQL suddenly turns off, my WordPress crashes it causing downtime. If I go home, I have to wait anywhere from a few hours to a few days until I go back home and log in to my computer and restart my server using manual means.

How to automatically restart MYSQL when it crashes in Aapanel

I am aware that SSH can be installed on my smartphone and I can log in through it and restart my server.

But shouldn’t MySQL restart by itself when it crashes? Sure not, but is there another easy way that can be done to restart automatically every time it goes down? let’s take a look at the tutorial.

Step by Step automatically restart MYSQL in aapanel

  1. Open your aapanel dashboard
  2. Go to the cron section
  3. Add CronJob
  4. In Type of Task select Shell Script
  5. Execution cycle 5-10 minutes
  6. Fill Script content:


# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it’s not running.
if [ $? != 0 ]; then
/bin/systemctl restart mysql.service


To test, turn off MySQL, try turning on the script by selecting execute

I’m using Centos OS on my server

If you have difficulty practicing it, write in the comments section the problem you encountered.

Read More: How Migrate AAPanel using One-Click Migration API version 3.0