我现在的方法比较耗时,因前面数据id连续递增,到跳的id时不停增加id值以及对比此id创建日期,这样推断有无空的id,然后在查询起始和结束id不超过一定范围,比如5亿条数据量以内作为一次导出。
select count(id) from xxx where id > 5730055060275318 and id <= 5730055600000000
460307296
select created_time from xx where id = 5730055060275318;
2022-07-19 04:50:39
select created_time from produce_param where id = 5730055600000000;
2022-07-21 06:58:31
当时一个分段对比数据脚本改了一下,就当前的问题你看对你有帮助没:
minid=mysql -h -u -p -e"select min(id) from t"
maxid=select max(id) from t
ksid=$minid
let zjid=($maxid-$ksid)/2
let jzid=$ksid+$zjid
while ture
do
sycount=mysql -h -u -p -e"select count(*) from t where id=>$ksid and id <=$maxid"
if [[ “$sycount” -gt “10” ]];then
count=select count(*) from t where id=>$ksid and id <$jzid
while ture
do
if [[ “$count” -gt “10” ]];then
let zjid=$zjid/2
let jzid=$ksid+$zjid
count=mysql -h -u -p -e"select count(*) from t where id=>$ksid and id <$jzid"
else
echo “select * from t where id=>$ksid and id <$jzid”
let ksid=$jzid
let zjid=($maxid-$ksid)/2
let jzid=$ksid+$zjid
break
fi
done
else
echo “select * from t where id=>$ksid and id <$jzid”
exit
fi
done