mysql数据库批量更新脚本
时间:2010-06-26 来源:hg1995
公司用的是linux+mysql,最近老是有更新,今天添加个表,明天删除条记录,由于服务器较多,所以不胜其烦,懒人总有懒办法,于是写了一个小脚本实现。
#!/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` ; ...... about the other server,you may add it yourself.
## 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` ; ...... about the other server,you may add it yourself.
相关阅读 更多 +