Check whether mysql is successfully started (bat + bash), mysqlbash

Source: Internet
Author: User

Check whether mysql is successfully started (bat + bash), mysqlbash

Many of my friends prefer windows. For more information, see the following code.

Method 1: Skip

@echo off for /f "usebackq" %%i in (`"tasklist|find /c "mysqld.exe""`) do ( set chkstat=%%i ) if %chkstat% == 0 ( net start mysqlecho ================ >> %date:~0,10%.log echo %date% %time% check mysql service stop >> %date:~0,10%.log echo restart mysql service! >> %date:~0,10%.log echo ================ >> %date:~0,10%.log ) 

Method 2:

@ Echo offfor/f "skip = 3 tokens = 4" % I in ('SC query mysql') do set "zt = % I" & goto: next: nextif/I "% zt %" = "RUNNING" (echo has found that the service is RUNNING and is shutting down the service net stop mysql) else (echo this service is now processing stopped, enabling the Service net start mysql) exitpause

Use shell commands in linux

Checks whether MySQL is down. If it is down, it is started.

If your MySQL database goes down frequently, you can use this script to automatically start it after it goes down and add it to the crontab for execution.
See http://www.codeproject.com/Articles/988967/Mysql-Uptime-Check-Script for more information

#!/bin/bash result=`/usr/bin/mysqladmin ping`expected='mysqld is alive' if [[ "$result" != "$expected" ]]thenecho "It's dead - restart mysql" # email subjectSUBJECT="[MYSQL ERROR] - Attempting to restart service" # Email To ?EMAIL="info@endyourif.com" # Email text/messageEMAILMESSAGE="/tmp/emailmessage.txt"echo "$result was received"> $EMAILMESSAGEecho "when we were expected $expected" >>$EMAILMESSAGE# send an email using /bin/mailmail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE sudo /etc/init.d/mysql restartfi

Method 2,

#!/bin/bash#mysql checkPORT="0"PORT=`netstat -lnt | grep 3306 | wc -l `echo $PORTif [ $PORT -eq 1 ] thenecho "mysql is running"elseecho "mysql is not running"echo "progrome reeady to start mysql "sudo service mysql start./check_mysql.shfi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.