此脚本是对一个大表使用自增id进行范围导出,限制一次导出的行数
1 #!/bin/bash 2 3 mysqlhost="192.168.2.35" 4 mysqlport="3306" 5 mysqluser="work" 6 mysqlpassword=‘password‘ 7 log_dir=‘/home/mcpuserinfo/mcp_user_info‘ 8 qrow=200000 9 10 11 mkdir -p $log_dir 12 13 14 15 maxid=`mysql -h$mysqlhost -P$mysqlport -u$mysqluser -p$mysqlpassword -Dmcp_user -N -e "select max(User_Id) from mcp_user.mcp_user_info"` 16 17 beginid=0 18 endid=`expr $beginid + $qrow` 19 20 while [[ $beginid -lt $maxid ]] 21 do 22 23 mysqldump -h$mysqlhost -P$mysqlport -u$mysqluser -p$mysqlpassword mcp_user mcp_user_info --opt --default-character-set utf8 -N -e --where=" User_Id>=$beginid and User_Id<$endid" > $log_dir/mcp_user_info-${beginid}-${endid}.sql 24 echo `date ‘+%Y-%m-%d %H:%M:%S‘`" mcp_user_bd_eb ["$beginid","$endid")" 25 beginid=$endid 26 endid=`expr $beginid + $qrow` 27 done
原文:https://www.cnblogs.com/fuyuntao/p/10823996.html