删除大量数据时报错"ERROR 2013 (HY000): Lost connection to MySQL server during query"

给你个脚本可以大规模删除数据
date1=date -d “1 day ago” +“%Y-%m-%d”
echo $date1
delete_db_sql=" delete from xxxx a where a.xxxx < ‘2023-01-01 00:00:00’ and a.xxxx = ‘2’ limit 10000;"
echo $delete_db_sql
i=0

while ((++i)); do
a=$(/bin/mysql -uroot -pxxxx -A soa_vehicle -hx.x.x.x -P 4000 --comments -e “${delete_db_sql}” -vvv|grep “Query OK” |awk ‘{print $3}’)
echo $a
if (($a<1)); then
break 1
fi
sleep 1
printf “%-4d” $((i))
done

2 个赞