Bash Script To Restart mysql Ubuntu 14.04
Hello,
I need a Bash Script To Restart mysql, can someone help please ?
Thank you very much!
Hello,
I need a Bash Script To Restart mysql, can someone help please ?
Thank you very much!
Kamal,
my MYSQL is down 10 times for day, for this reason I need the bash script.
I've this 2 bash script in the /root :
#!/bin/sh
ps auxw | grep apache2 | grep -v grep > /dev/null
if [ $? != 0 ]
then
/etc/init.d/apache2 start > /dev/null
fi
#!/bin/bash
if [[ ! "$(service mysql status)" =~ "start/running" ]]
then
service mysql start
fi
None working properly
You can help me please?
Thank you very much
I would recommend finding out why MySQL is crashing in the first place and solving that instead of working around it and just restarting it and then having it crash again.
Check MySQL's error log, what's the output of this command?
sudo tail -30 /var/log/mysql.err
You can restart MySQL by running sudo service mysql restart
. You don't need a bash script, you can just run that command. Is that what you need?
Hey - I had this issue, but I only wanted to restart mysql if it had stopped.
To simply restart MySQL you can add the following to the root CRONTAB:
This restarts every minute:
If you want to check if MySQL is running first, and start it if it isn't, then you could add this to the crontab:
PS add this if you want to stop it emailing you the results of every time cron runs the script: