• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

java 驱动mysqldump 开展自动备份

mysql 搞代码 7年前 (2018-06-06) 158次浏览 已收录 0个评论

java 驱动mysqldump 进行自动备份
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;

public class MysqlDump1 {
private String ip;
private String port;
private String database;
private String user;
private String pass;
private String path;

public MysqlDump1(String ip, String port, String database, String user,
String pass, String path) {
super();
this.ip = ip;
this.port = port;
this.database = database;
this.user = user;
this.pass = pass;
this.path = path;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public String getPort() {
return port;
}

public void setPort(String port) {
this.port = port;
}

public String getDatabase() {
return database;
}

public void setDatabase(String database) {
this.database = database;
}

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

public String getPass() {
return pass;
}

public void setPass(String pass) {
this.pass = pass;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public void export(){
String dumpCommand = “mysqldump ” + database + ” -h ” + ip + ” -u ” + user +” -p” + pass;
Runtime rt = Runtime.getRuntime();
File test=new File(path);
PrintStream ps;

try{
Process child = rt.exec(dumpCommand);
ps=new PrintStream(test);
InputStream in = child.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
ps.write(ch);
System.out.write(ch); //to view it by console
}

InputStream err = child.getErrorStream();
while ((ch = err.read()) != -1) {
System.out.write(ch);
}
}catch(Exception exc) {
exc.printStackTrace();
}
}

public static void main(String args[]){
MysqlDump1 md=new MysqlDump1(“localhost”,”3306″,”materials”,”root”,”root”,”E://materials.sql”);
md.export();
}
}


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:java 驱动mysqldump 开展自动备份

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址