第一种方法:利用mysql命令查看
MySQL 内建直接看 status 就可以看到系统常见讯息, 如下述范例:
复制代码 代码如下:
1.$ mysql -u root -p
2.mysql> s
“Threads: 2 Questions: 224857636 Slow queries: 229 Opens: 1740 Flush tables: 1 Open tables: 735 Queries per second avg: 137.566
$ mysql -u root -p -e "status" # s = status,
用这个也会列出上述结果.
第二种方法:利用phpmyadmin查看
最简单的方式,在phpMyAdmin直接点击状态查看
这查看的是MySQL的一些运行状况数值,这种方式被大多数系统管理员所不齿,因为专业的MySQL服务器很少有能通过phpMyAdmin访问的,后面会介绍其他查看方式,但是phpMyAdmin提供优化建议还是很具有指导性和参考性的。
检查mysql是否成功启动
?
123456789101112131415 | #!/bin/bash #mysql check PORT= "0" PORT=` netstat -lnt | grep 3306 | wc -l ` echo $PORT if [ $PORT - eq 1 ] then echo "mysql is running" else echo "mysql is not running" echo "progrome reeady to start mysql " sudo service mysql start . /check_mysql .sh fi |
检测 MySQL 是否宕掉,如果宕掉则启动
如果你的 MySQL 经常宕机,可以用这个脚本来实现宕机后自动启动,把它加到 crontab 里执行即可。
详细介绍请看 http://www.codeproject.com/Articles/988967/Mysql-Uptime-Check-Script
?
123456789101112131415161718192021222324 | #!/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版
?
12345678910111213 | @ 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 |
经测试有时候不是很好用。