写了一个简单的shell/ target=_blank class=infotextkey>shell脚本,实现mysql 批量更新数据,因为更新的是远程主机上的数据,所以需要ssh连接权限。
shell脚本:
#!/bin/bash
## this script is made for update mysql
## please run it as root
## please set ssh remote login whitout password (use ssh-keygen)
## 2010.6.26
## set local sql file path
LOCAL_FILE='/home/script/update_db.sql'
## set remote sql file path
REMOTE_FILE='/tmp/update_db.sql'
## set mysql password
PASSWORD='your password'
## server 192.168.2.20 |
## database name db1,db2
scp ${LOCAL_FILE} 192.168.2.20:${REMOTE_FILE}
db1="ssh 192.168.2.20 'mysql -uroot -p${PASSWORD} db1 < ${REMOTE_FILE}'" ;
db2="ssh 192.168.2.20 'mysql -uroot -p${PASSWORD} db2 < ${REMOTE_FILE}'" ;
`eval $db1` ;
`eval $db2` ;