JAVA程序实现mysql定时导出和导入库程序

前言

首先,用的环境是MYSQL5和JDK1.6。通过JDK所带的TIME类来进行定时定点的定时器,在通过JAVA链接数据库导出数据库的脚本。

BeiFen.java (数据库导入导出程序) 

public class BeiFen extends TimerTask {
    public voidrun() {
          BeiFen.main("数据库");
    }

    public static void main(String args) {
       // 数据库导出
       String user = "root"; // 数据库帐号
       String password = "root"; // 登陆密码
       String database = "test"; // 需要备份的数据库名
       String filepath = "e:\\SQL\\efeed1.sql"; // 备份的路径地址

       String stmt1 = "D:\\Program Files\\MySQL\\MySQL Server5.0\\bin\\mysqldump "
                      + database   +" -u " + user + " -p" + password + "
                      --result-file=" + filepath;

       try {
           Runtime.getRuntime().exec(stmt1);
           System.out.println("数据已导出到文件" + filepath + "中");
 

猜你喜欢

转载自blog.csdn.net/as4589sd/article/details/104198090
今日推荐