Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- database=""
- from_table=""
- dest_table=""
- batch_size=5000
- last_id=""
- user=""
- pwd=""
- i=0
- while [ true ]
- do
- t=$(( i*batch_size ))
- echo "last_id:$last_id $i $t"
- sql="REPLACE INTO ${database}.$dest_table SELECT * FROM ${database}.${from_table} where id > $last_id LIMIT ${batch_size}"
- echo $sql
- date
- mysql -u${user} -p${pwd} -e "$sql"
- new_id=`mysql -u${user} -p${pwd} -s -N -e "SELECT id FROM ${database}.${from_table} where id > $last_id LIMIT ${batch_size},1"`
- if [ -z $new_id ]
- then
- echo "done."
- break
- fi
- last_id=$new_id
- i=$(( i+1 ))
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement