java mysql 备份数据库
来源:互联网 发布:星际争霸 平衡性 知乎 编辑:程序博客网 时间:2024/05/17 04:13
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;
public class Backup extends TimerTask{
private String user_name;
private String user_psw;
private String db_name;
private String host_ip;
private String user_charset;
private String backup_path;
private String stmt;
static SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMddHHmmss");//完整的时间
public boolean BackupMysql(String user_name,String user_psw,String db_name,String host_ip,String user_charset,String backup_path){
this.user_name=user_name;
this.user_psw=user_psw;
this.db_name=db_name;
if(host_ip==null||host_ip.equals(""))
this.host_ip="localhost";
else
this.host_ip=host_ip;
if(user_charset==null||user_charset.equals(""))
this.user_charset=" ";
else
this.user_charset=" --default-character-set="+user_charset;
this.backup_path=backup_path;
this.stmt="C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump "+this.db_name+" -h "+this.host_ip+" -u"+this.user_name+" -p"+this.user_psw +this.user_charset+" --result-file="+this.backup_path;
boolean run_result=false;
try{
System.out.println("备份语句="+this.stmt);
Runtime.getRuntime().exec(this.stmt);
run_result=true;
System.out.println("------备份成功!-----");
}catch(Exception e){
e.printStackTrace();
}finally{
return run_result;
}
}
@Override
public void run() {
try{
System.out.println("数据库备份 --- 定时执行,开始时间为: " + new Date());
String path ="c:\\DataBaseBak"; //设置一个默认文件夹路径
File uploadFilePath = new File(path);
// 如果该目录不存在,则创建之
if(uploadFilePath.exists() == false) {
uploadFilePath.mkdirs();
System.out.println("路径不存在,但是已经成功创建了" + path);
}else{
System.out.println("文件路径存在" + path);
}
String time=sdf.format(new Date());
System.out.println("---"+time);
BackupMysql("root","sasa","jforum","10.5.1.103","utf8",path+"\\jforum"+time+".sql");
System.out.println(" 数据库备份 --- 定时执行,结束时间为: " + new Date());
}catch (Exception e) {
}
}
}
- java备份mysql数据库
- java 备份mysql数据库
- java mysql 备份数据库
- java 备份mysql数据库
- Java备份Mysql数据库
- Java备份Mysql数据库
- java备份还原mysql数据库
- java 程序备份MySQL数据库
- Java备份还原Mysql数据库
- java 备份还原 mysql 数据库
- mysql数据库备份--java代码
- java mysql数据库备份还原
- java关于mysql数据库备份
- Java备份还原Mysql数据库
- java备份还原mysql数据库
- java 实现mysql数据库备份
- java恢复备份mysql数据库
- mysql数据库备份--java代码
- CvSeq的理解(转载)
- VS2008中"fatal error C1083:无法打开包括文件:“Stdafx.h”: No such file or directory”
- ADF Task Flow bounded task flow中创建页面片段 生成Region情况
- window配置php环境,选用Apache服务器
- 使用dulilib DirectUI库(一)
- java mysql 备份数据库
- Fully buffered & Line buffered & Unbuffered
- iOS----delegate和Notification的区别
- error C2471: 无法更新程序数据库
- 第78天的交易(2013-8-14)(-50)(-143.28)(数据单总盈利:-108.65)
- Subversion 出现 301 Moved Permanently 的解决方法
- VS2008 1>mt.exe : general error c101008a: Failed to save the updated manifest to the file
- https工作原理和http协议
- linux find 与grep结合使用