导数据和同步数据脚步

越来越懒了,根据公司业务写了一个导如MySQL数据库数据的脚步,第一个是导入数据,第二个是将公网一个表同步到本地局域网。

 

 

 

#!/bin/bash
#Creation Date:2010-8-6
#Author:wubolu



read -p "Please inupt filename:" filename
if test -f /tmp/$filename;then
echo "Please wait ..."
/usr/local/mysql/bin/mysql -u NAME --password='PASSWORD' << EOFMYSQL
use gk2010;
truncate table lq;
set names utf8;
load data infile '/tmp/$filename' into table gk2010.lq fields terminated by ',' enclosed by '"' lines terminated by '\r\n' ignore 1 lines;
update lq,cj set lq.csny=cj.csny where lq.zkzh=cj.zkzh;
quit;
EOFMYSQL
echo -e
\\n +-------------------------------------------------------+

echo " Done, thank you for choosing wubolu's shell script!"
echo -e +-------------------------------------------------------+\\n


else
echo "/tmp/$filename  No such file."
fi
exit 0

 

 

(以下脚步运行前提是建立两服务器间通信免密码信任,具体设置请看 http://wubolu.iteye.com/blog/707572

 

#!/bin/bash

#Creation Date:2010-8-6
#Author:wubolu


rm -rf /usr/local/mysql/data/gk2010/lq.*;
scp -C
[email protected]:/usr/local/mysql/var/gk2010/lq .* /usr/local/mysql/data/gk2010/;
chown mysql:mysql /usr/local/mysql/data/gk2010/lq.*;
/usr/local/mysql/bin/mysql -u NAME --password='PASSWORD' << EOFMYSQL
use gk2010;
flush table lq;
EOFMYSQL
echo -e
\\n +-------------------------------------------------------+
echo "|  Done, thank you for choosing wubolu's shell script!      |"
echo -e +-------------------------------------------------------+\\n

你可能感兴趣的:(C++,c,mysql,C#,bash)