MySQL Database dump using java

Why are you wasting the time by taking backup manually ?
I have a very good suggestion for people taking daily backup manually and spending lot of time.

I am giving you a script for taking backup with ease.

Run the below script and save your precious time.

  1. Set mysql path in your /etc/profile environment file
  2. add the script export PATH=/usr/local/mysql/bin:$PATH at the end of the file – needed for mysqldump to run through java
  3. script to take the mysql backup from the shell/terminal
  4. user@localhost:/usr/local/mysql/bin$ mysqldump -u user -u password database > backup.sql

mysqldump using java to take database backup.

import java.io.*;
public class MysqlDump {
public MysqlDump() {
try {

Runtime rt = Runtime.getRuntime();
rt.exec(“mysqldump -uuser -ppassword database -r /home/user/backup.sql”);
} catch(IOException ioe) {
ioe.printStackTrace();
}catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String args[]) {
new MysqlDump();
}
}

Replace the word user and password with your actual database user name and password.

Contact me if you want any help at imamoo(at)ipott(dot)com

VN:F [1.1.4_465]
Rating: 3.0/5 (1 vote cast)

Leave a comment for: "MySQL Database dump using java"

Tag Cloud