第一种方法:利用mysql命令查看
MySQL 内建直接看 status 就可以看到系统常见讯息, 如下述范例:
#!/bin/bash result=`/usr/bin/mysqladmin ping` expected=\'mysqld is alive\' if [[ \"$result\" != \"$expected\" ]] then echo \"It\'s dead - restart mysql\" # email subject SUBJECT=\"[MYSQL ERROR] - Attempting to restart service\" # Email To ? EMAIL=\"info@endyourif.com\" # Email text/message EMAILMESSAGE=\"/tmp/emailmessage.txt\" echo \"$result was received\"> $EMAILMESSAGE echo \"when we were expected $expected\" >>$EMAILMESSAGE # send an email using /bin/mail mail -s \"$SUBJECT\" \"$EMAIL\" < $EMAILMESSAGE sudo /etc/init.d/mysql restart fi
Mysql bat启动和关闭服务bat版
@echo off for /f \"skip=3 tokens=4\" %%i in (\'sc query mysql\') do set \"zt=%%i\" &goto :next :next if /i \"%zt%\"==\"RUNNING\" ( echo 已经发现该服务在运行,正在已经关闭服务 net stop mysql ) else ( echo 该服务现在处理停止状态,正在现在开启服务 net start mysql ) exit pause
经测试有时候不是很好用。
本文地址:https://www.stayed.cn/item/24602
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我