当前位置: 代码迷 >> 综合 >> Shell 定时脚本处理 Mysql 表的 Incorrect file format 损坏
  详细解决方案

Shell 定时脚本处理 Mysql 表的 Incorrect file format 损坏

热度:41   发布时间:2024-01-24 06:47:48.0

 陆续有 N 此了,每次服务器自动重启后,某个数据库内的一张表会出现正在使用中的状态,然后对其修复会报以下提示:

Incorrect file format 'ac_allow' 

 虽然可以经过手动清空表,或者执行以下操作修复,但是每次服务器重启后依然会有该问题,引起不小的一定时间内的故障。

REPAIR TABLE ac_allow USE_FRM

 然后心想,写一个定时脚本,一个小时内执行一次,反正也消耗不了太多的资源,避免发生长时间故障。

#!/bin/bashcmd="select count(*) from linux.test"
rest_table="REPAIR TABLE linux.test USE_FRM"
cnt=$(mysql -uroot -p5d04d94 -s -e "${cmd}")if [[ ${cnt} =~ 'Incorrect file format' ]]
thenecho 'mysql down';res=$(mysql -uroot -p5d04d94 -s -e "${rest_table}")echo $res;
elseecho 'mysl is ok';
fiexit 

按照以上脚本修改对应的数据库和表,然后添加定时任务即可。

  相关解决方案