How to start MySQL automatically if that stop for any reason?

Little Alien

Member
Registered
Joined
Jul 4, 2016
Messages
38
Points
0
With VPS has less RAM and your websites can face with the problem is the MySQL automatically stop sometimes leads to overloading and faulty website can not connect to the database. There are many ways to restart MySQL automatically if that stop for any reason?
 

ValeriaMxc

New member
Registered
Joined
Oct 12, 2012
Messages
12
Points
0
MySQL commands to enable services automatically

On VPS Centos

Centos 6 (MariaDB) :

Code:
service mysql start
or

Code:
/etc/init.d/mysql start
Centos 7:

MySQL:

Code:
systemctl start mysql.service
MariaDB:

Code:
systemctl start mariadb.service
On VPS Ubuntu

Code:
/etc/init.d/mysql start
or

Code:
/etc/init.d/mysqld start
Depends on your OS, you can choose mysql or mysqld according.

Otherwise, you can create a Crontab to restart your MySQL automatically aftrer a crash or reboot.
 

ceapa

New member
Registered
Joined
Jul 25, 2016
Messages
6
Points
0
Assuming that to want to restart a MySQL server automatically after a crash I would do something like this: set a cronjob which check every 10 minutes if MySql server is on! If not, then run a bash command which will start it (e.g.: Debian/Ubuntu: service mysql restart).

So, the bash script would be:
Code:
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
        echo "MySQL is down.";
        sudo service mysql start

else
        echo "All is well.";
fi
monitor.sh >> https://gist.github.com/mheadd/5571023

Then set a cron job run this job every interval you want, in my example 5 minutes:
Code:
*/5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1
Eventually you may want to receive an email to inform you when sql server crash with the following bash script:
Code:
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
        mailx -s "Mayday mayday, SQL down!" < /dev/null "myself@maysite";
        sudo service mysql start

else
        echo "All is well.";
fi
 
Latest Threads
Recommended Threads
Replies
3
Views
2,199
Replies
16
Views
4,896
Replies
3
Views
1,994

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top