Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

bagaimana saya bisa mencadangkan dan memulihkan tanggal dari basis data mysql

import java.io.IOException;  
/**  
*  
* @author [email protected]  
*/  

public class DatabaseManager {  

public static boolean backup(String mysqldumpPath, String backupPath) {
    boolean status = false;
    String username = "name";
    String password = "pword";
    String database = "database_name";


    String command = "/" + mysqldumpPath + "/mysqldump -u " + username + " -p" + password + " " + database + " -r " + backupPath;
    try {
        Process runtimeProcess = Runtime.getRuntime().exec(command);
        int processComplete = runtimeProcess.waitFor();
        if (processComplete == 0) {
            System.out.println("DatabaseManager.backup: Backup Successfull");
            status = true;
        } else {
            System.out.println("DatabaseManager.backup: Backup Failure!");
        }
    } catch (IOException ioe) {
        System.out.println("Exception IO");
        ioe.printStackTrace();
    } catch (Exception e) {
        System.out.println("Exception");
        e.printStackTrace();
    }
    return status;
}
public static boolean restore(String filePath){
    boolean status = false;
    String username = "name";
    String password = "pword";
    String[] command = new String[]{"mysql", "database_name", "-u" + username, "-p" + password, "-e", " source "+filePath };

    try {
        Process runtimeProcess = Runtime.getRuntime().exec(command);
        int processComplete = runtimeProcess.waitFor();
        if (processComplete == 0) {
            System.out.println("DatabaseManager.restore: Restore Successfull");
            status = true;
        } else {
            System.out.println("DatabaseManager.restore: Restore Failure!");
        }
    } catch (IOException ioe) {
        System.out.println("Exception IO");
        ioe.printStackTrace();
    } catch (Exception e) {
        System.out.println("Exception");
        e.printStackTrace();
    }
    return status;
}

//for testing
public static void main(String args[]){
    String backupName = "D:/DatabaseBackup/backupHvs.sql";
    DatabaseManager.restore(backupName);
}

}


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Kirim ArrayList dari android ke php MySQL

  2. Tidak dapat mengimpor mysql-python di crontab Mac OS

  3. Pembuatan Database Visual dengan MySQL Workbench

  4. .Net MySql error Kunci yang diberikan tidak ada dalam kamus

  5. Nilai peningkatan MySQL