MySQL 批量更新、刪除資料shell指令碼

haoge0205發表於2019-12-26

#!/bin/bash

. ~/.bash_profile

log=/tmp/update_log_1_$(date +%F).log

vstart=1

step=100

vstop=$((${vstart}+${step}))

max=50000

USER='yoon'

PWD='yoon123!@#'

HOST=127.0.0.1

DB=yoon

PORT=3306

TB=employees_ptarc

echo "stop value is $vstop"

while [ ${vstart} -lt $((${max}+1)) ] 

do

        echo "`date +%F-%T`; /usr/local/mysql/bin/mysql -h${HOST} -u${USER} -p${PWD} -P${PORT} ${DB} -e\"UPDATE ${TB} set v_int=9 where id between ${vstart}  and ${vstop}\"" >> ${log}

        /usr/local/mysql/bin/mysql -h${HOST} -u${USER} -p${PWD} -P${PORT} ${DB} -e"UPDATE ${TB} set v_int=9 where id between ${vstart}  and ${vstop} "

        vstart=$((${vstop}+1))

        vstop=$((${vstop}+${step}))

        if [ ${vstop} -gt ${max} ]; then

                vstop=${max}

        fi

        sleep 1

        #echo "start at ${vstart}, stop at ${vstop}"

done


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-2670806/,如需轉載,請註明出處,否則將追究法律責任。

相關文章