##密码中的特殊符号需要转义。
##一条命令只能操作一张表。
写成shell脚本以供调用:
#!/bin/bash if [ $# -eq 0 ]; then echo 'Please specify dbname, tablename, like: dbname.tablename' exit 1 fi #or for i in $@ do .... done #while [[ $# -gt 0 ]] #do #param=$1 #shift #done function doExport { db=$1 tbl=$2 where=$3 opt=$4 if [[ -z $db || -z $tbl ]]; then echo "Db and Table required" exit 1 fi if [[ -z $where ]]; then echo "Please specify condition, if non, input 1" exit 1 fi if [[ -z $4 ]]; then opt="" elif [[ "$4"x = "c"x ]]; then opt="--no-create-info" else opt="-d" fi `mysqldump -hlocalhost -P3306 -umyroot -pmypwd\!db2009\$ -C --single-transaction $opt --opt $db $tbl --where="$where" > ~/sql/$db.$tbl.sql` cd ~/sql/ tar -cvzf $db.$tbl.sql.tar.gz $db.$tbl.sql } doExport $1 $2 $3 $4