当前位置:Gxlcms > mysql > 检查并修复mysql数据库表_MySQL

检查并修复mysql数据库表_MySQL

时间:2021-07-01 10:21:17 帮助过:23人阅读

bitsCN.com

检查并修复mysql数据库表

01

#!/bin/sh

02

#code by scpman

03

#功能:检查并修复mysql数据库表

04

#将此脚本加到定时中,脚本执行时,等会读库,列出要修复的所有表,然后计时,开始修复

05

#修复过程中将损坏的表记录下来,修复完成后,将损坏的表,发邮件通知。

06

fix_logs='/tmp/fix.log'

07

user=''

08

pass=''

09

check_fix()

10

{

11

dblist=`/usr/bin/find /usr/dlm_db/mysql/ -type d | grep -vE "logs|_[1-9]|*bak|test"| sed -e "s#/usr/dlm_db/mysql/##g"`

12

echo start `date`>$fix_logs

13

for dbname in $dblist

14

do

15

echo $dbname

16

for tb_name in `/usr/bin/find /usr/dlm_db/mysql/$dbname -type f | awk -F'/' '{print $NF}' | awk -F'.' '{print $1}' | sort -

17

u`

18

do

19

mysql -u$user -p$pass $dbname<>$fix_logs

20

check table $tb_name;

21

repair table $tb_name;

22

FFF

23

done

24

done

25

echo `date` done>>$fix_logs

26

}

27

send_logs()

28

{

29

msgip=10.0.7.44

30

IP=`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p `

31

fix_info=`grep -rE "Error|start|done" $fix_logs`

32

/usr/bin/logger -p local1.info -h $msgip "the services: $IP mysql_table_fix_info:$fix_info"

33

}

34

check_fix

35

send_logs

bitsCN.com

人气教程排行