以表名为ztask_1_XXX为例, 统计各表中符合条件的记录数,最大程度上使用shell和mysql命令,达到批量操作的目的。
同样,删除符合条件的记录等也可通过替换select count(1)来达到。
#/bin/bash
table_list=$(mysql -hXX -uxxe -pexinie db_name -e "show tables" | grep ztask_1_); // -e 执行mysql 命令
for table in $table_list;
do echo $table;
mysql -hXX -uxxe -pexinie db_name -e " select count(1) from db_name.$table where next_try_time < 1501329600 and progress = 5 and column_name_N like'%failed%'";
done;