public static void backup() {
// 数据库导出
String user = "xiaohuan"; // 数据库帐号
String password = "xiaohuanjie"; // 登陆密码
String database = "srms"; // 需要备份的数据库名
String filepath = "d:/xiao.sql"; // 备份的路径地址
// 注意mysqldump是调用mysql数据库的一个组件,在未在系统变量中声明的话,要在这里写mysqldump的完整路径
String stmt1 = "mysqldump " + database + " -u " + user + " -p"
+ password + " --result-file=" + filepath;
try {
Runtime.getRuntime().exec(stmt1);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void load() {
String filepath = "d:/xiao.sql"; // 备份的路径地址
// 新建数据库srms
String stmt1 = "mysqladmin -u xiaohuan -pxiaohuanjie create srms";
String stmt2 = "mysql -u xiaohuan -pxiaohuanjie srms < " + filepath;
String[] cmd = { "cmd", "/c", stmt2 };
try {
Runtime.getRuntime().exec(stmt1);
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// backup();
load();
}