1. 导出zkt_crm的指定表名
#!/usr/bin/env bash
if [ "$#" -lt 1 ]; then
echo "Usage: $(basename $0) [table_name]";
exit
fi
tableName=$1
/opt/lampp/bin/mysqldump -uroot -h172.16.0.224 --port 3308 --databases zkt_crm -ptest1111 \
--tables ${tableName} > ${tableName}.sql
#echo "param num:$#"
#echo "shell file: $(basename $0)"
#echo "hello world $1 !"
用法:
bash tbl_dump.sh 5kcrm_admin_field
cat 5kcrm_admin_field.sql
如果是windows系统:
tbl_dump.bat
@echo off
rem set tableName=5kcrm_admin_field
set cnt=0
if "%1"=="" (
echo Usage: %0 [table_name]
goto :end
)
set tableName=%1
rem echo %tableName%
D:\opt\xampp\mysql\bin\mysqldump.exe -h172.16.0.224 ^
-uroot ^
-ptest1111 ^
--port 3308 ^
--databases zkt_crm ^
--tables %tableName% > %tableName%.sql
:end
2. 把easy_eyes数据库的所有表导出 一个表一个表名.sql文件
* dump.sh
#!/usr/bin/env bash
DUMP="/opt/lampp/bin/mysqldump"
CONN="-uroot -h10.0.0.134 --databases easy_eyes -pXXXXXX"
${DUMP} ${CONN} > easy_eyes.sql
tables=(config admin rules users warn)
# for ((i = 0; i < ${#tables[@]}; i++)) do echo ${tables[i]}; done
for tbl in ${tables[@]}; do
${DUMP} ${CONN} --tables ${tbl} > "easy_eyes.${tbl}.sql"
done
* test
bash dump.sh