1. 程式人生 > >linux下用shell腳本刪除mysql記錄ssc源碼搭建

linux下用shell腳本刪除mysql記錄ssc源碼搭建

sed caused mit mysq 腳本 don bash jdb use

mysql下刪除記錄較多的ssc源碼搭建會出現如下錯誤:企 娥:217 1793 408

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

因此需要分批刪除表中數據,腳本如下:

#!/bin/bash
DB_USER="root"
DB_PASS="pw"
DB_HOST="10.228.221.25"
DB_NAME="tjxx"

PORT="3306"

echo "Sql start" >> /home/xxf/log.txt

timeS=date "+%Y-%m-%d"
echo "${timeS}" >> /home/xxf/log.txt

delete_sql="delete from region_stastics_history where time < ‘${timeS}‘ order by id limit 1000;"

#mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P${PORT} $DB_NAME -e "${delete_sql}"

count=0
while [ $count -le 500 ];do
echo $count >> /home/xxf/log.txt
mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P${PORT} $DB_NAME -e "${delete_sql}"
count=$((count + 1))
done
echo "Sql End" >> /home/xxf/log.txt

linux下用shell腳本刪除mysql記錄ssc源碼搭建