backup mysql database java code

前端 未结 3 905
终归单人心
终归单人心 2020-12-10 19:12

I tried to run the following code which is to create a backup of my database but it shows some run time errors.

But, I tried to run the Syst

3条回答
  •  情书的邮戳
    2020-12-10 19:59

    I solved this problem by giving full path to mysqldump.exe

    You can get SO environment variables by

    Map env = System.getenv();
    final String LOCATION = env.get("MYSQLDUMP");
    

    I setup the system variable like this :

    • Variable Name : MYSQLDUMP
    • Value : D:\xampp\mysql\bin\mysqldump.exe

    Now just execute this code below,

    String executeCmd = LOCATION+" -u " + DBUSER + " --add-drop-database -B " + DBNAME + " -r " + PATH + ""+FILENAME
    Process runtimeProcess = = Runtime.getRuntime().exec(executeCmd);
    

    Note : If you don't have configured password for mysql server just remove the -p PASSWORD attribute from the code. And don't forget to restart your computer after creating a new system variable.

提交回复
热议问题