groovy中备份和恢复mysql数据库
groovy/Java执行的windows命令行如果包含尖括号会出现错误, 可以采取以下两种方法解决:
1) 加 "cmd", "/C"到命令前面。
备份mysql数据库采用
def myCommandString = ["cmd","/C","C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump", "-u****","-p****","dbname>c:/backup.sql"] Process proc = myCommandString.execute()
恢复mysql数据库采用
def myCommandString = ["cmd","/C","C:/Program Files/MySQL/MySQL Server 5.5/bin/mysql", "-u****","-p****","dbname<c:/backup.sql"]
2) 用其他命令代替<>.
备份mysql数据库采用
def myCommandString = "C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump --opt -u*** -p*** dbname --result-file=c:/backup.sql" Process proc = myCommandString.execute() proc.waitFor()
恢复mysql数据库采用
def p2 = "C:/Program Files/MySQL/MySQL Server 5.5/bin/mysql -u*** -p*** dbname".execute() p2.withWriter { writer -> writer << 'source c:/backup.sql' } p2.waitFor()
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
bianruifeng 2020-11-16
云中舞步 2020-11-12
世樹 2020-11-11
暗夜之城 2020-11-11
Coder技术文摘 2020-09-29
huacuilaifa 2020-10-29
Gexrior 2020-10-22
tufeiax 2020-09-03
疯狂老司机 2020-09-08
王艺强 2020-11-17
aydh 2020-11-12
zry 2020-11-11
URML 2020-11-11
spurity 2020-11-10
yifangs 2020-10-13
Andrea0 2020-09-18
Ida 2020-09-16
ltd00 2020-09-12
xjd0 2020-09-10