linux中MySQL监控脚本方法介绍

最简的办法端口判断法==>仅适合数据库本地使用
法1:if条件判断方法

 代码如下 复制代码

[root@oldboy scripts]# cat check_db01.sh
#!/bin/sh
#created by oldboy
#mail:oldboy521@gmail.com
PortNum=`netstat -lnt|grep 3306|wc -l`
if [ $PortNum -eq 1  ]
then
   echo "mysqld is running."
else
   echo "mysqld is stoped."
fi

例2模拟用户(包括web server)访问方法==>适合在远端服务器使用(本地也适合)

 代码如下 复制代码
[root@oldboy scripts]# cat check_db04.sh
#!/bin/sh
#created by oldboy
#mail:oldboy521@gmail.com
 
mysql  -S /data/3306/mysql.sock -e "select version();" >/dev/null 2>&1
if [ $? -eq 0 ]
then
   echo "mysqld is running."
else
  echo "mysqld is stoped."
fi

技巧:
1)使用web 连接账号模拟访问。

例3

 代码如下 复制代码

#!/bin/sh
MailList="xxx@test.com"
 
DBDataDir="/usr/local/mysql/var"
 
DBPort="3306"
 
IP=`ifconfig  | grep  'inet addr:' -m 1 | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;
 
ErrFile="$DBDataDir/$HOSTNAME.err"
 
ErrLine=`cat $ErrFile | wc -l`
 
GetDate=`date '+%Y-%m-%d %H:%M:%S'`
if [ ! -e /tmp/dberrline$DBPort ]
then
echo "$ErrLine" >/tmp/dberrline$DBPort
echo "Run it first!"
exit
fi
 
OldLine=`cat /tmp/dberrline$DBPort`
echo "$ErrLine" >/tmp/dberrline$DBPort
 
if [ "$ErrLine" -gt "$OldLine" ]
then
 
TailLine=`expr $ErrLine - $OldLine`
ErrStr=`tail -$TailLine "$ErrFile"`
 
LeftStr=`echo "$ErrStr" | sed '/InnoDB: ERROR: the age of the last checkpoint is/d' | sed '/InnoDB: which exceeds the log group capacity/d' |sed '/InnoDB: If you are using big BLOB or TEXT rows, you must set the/d' | sed '/InnoDB: combined size of log files at least 10 times bigger than the/d' | sed '/InnoDB: largest such row./d'`
 
if [ "$LeftStr" != "" ]
then
echo "$LeftStr" |mutt -s "Something wrong with $HOSTNAME-$IP($DBPort)!" ${MailList}
echo "$LeftStr"
fi
fi

上面的代码不能做什么其它及时提醒工具,如果需要我还可参考下面的办法

时间: 2024-07-31 16:59:34

linux中MySQL监控脚本方法介绍的相关文章

linux中配置安装redis方法介绍

redis的安装不需要 ./configure, 这点比较好, 简单!      代码如下 复制代码 #下载 wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz #解压 tar -zxvf redis-2.6.14.tar.gz #拷贝到目标目录 mkdir -p /usr/local/redis cp -r ./redis-2.6.14 /usr/local/redis cd /usr/local/redis #安装 make

linux中munin监控redis教程介绍

1,下载munin redis插件 https://github.com/bpineau/redis-munin 2,加载redis插件 # ln -sf /路径/redis_ /etc/munin/plugins/  3,创建munin的redis配置文件 # vim /etc/munin/plugin-conf.d/redis //新增文件  [redis_*]  user root     //在这里要root用户  env.host 127.0.0.1  env.port 6379  C

在Linux中通过Python脚本访问mdb数据库的方法

  这篇文章主要介绍了在Linux中通过Python脚本访问mdb数据库的方法,本文示例基于debian系的Linux系统,需要的朋友可以参考下 在 linux 系统中连接 mdb 数据库,直接连接的话,mdb 默认的驱动无法识别非 windows 的路径, 所以不能使用常规的连接方式 ? 1 DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:dirfile.mdb 安装 这里我们需要借助一些库来实现第三方的驱动 我们需要安装这些包:mdbtools,

实现Linux中Mysql数据库自动备份并上传到远程FTP服务器

这篇文章很有分享价值,因为我们在实际的生产环境中需要将数据库进行自动备份,然后上传到指定的位置,当然也可以像以下文章中所讲的一样,上传到你指定的FTP服务器中,从而实现Mysql数据库自动备份并上传到远程FTP服务器的部署,在Linuxhttp://www.aliyun.com/zixun/aggregation/31093.html">技术交流群中,也有朋友会遇到这方面的问题,可以将此文分享给群友共益. 注意:任何的操作都会具有风险性,请在本机实际测试通过之后再部署到服务器环境,这样即熟

linux忘记mysql密码找回方法

linux忘记mysql教程密码找回方法 今天我们主要是讲一下关于linux忘记mysql密码处理方法,下面提供了5种linux忘记mysql密码找回方法哦. 方法一: # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql> update user set password=password('newpass

Linux中fdisk分区使用方法

实例解说Linux中fdisk分区使用方法 一.fdisk 的介绍 fdisk - Partition table manipulator for Linux ,译成中文的意思是磁盘分区表操作工具:本人译的不太好,也没有看中文文档:其实就是分区工具. fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统,比如linux .fat32. linux .linux swap .fat16 以及其实类Unix类操作系统的文件系统等:当然我们用fdisk 对磁盘操作分区时,并不是一个

pyinotify:在Linux中实时监控文件系统更改

Pyinotify 是一个简单而有用的 Python 模块,它可用于在 Linux 中实时监控文件系统更改. 作为一名系统管理员,你可以用它来监视你感兴趣的目录的更改,如 Web 目录或程序数据存储目录及其他目录. 它依赖于 inotify(在内核 2.6.13 中纳入的 Linux 内核功能),它是一个事件驱动的通知程序,其通知通过三个系统调用从内核空间导出到用户空间. pyinotiy 的目的是绑定这三个系统调用,并在其上提供了一个通用和抽象的方法来操作这些功能. 在本文中,我们将向你展示如

linux忘记mysql密码处理方法_Mysql

linux忘记mysql密码处理方法: # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql> update user set password=password('newpassword') where user='root'; mysql> flush privileges; mysql> q

Linux开启mysql远程连接方法与问题解决办法

Linux开启mysql远程连接方法 1.GRANT命令创建远程连接mysql授权用户root mysql -u root -p mysql>GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123456' WITH GRANT OPTION; 增加root用户授权通过本地机(localhost)访问,密码 "123456". mysql>GRANT ALL PRIVILEGES ON *.* TO r