wishman wishman - 2 months ago 9
MySQL Question

How to restore a MySQL database backup using Java

I was able to create a backup of my current mysql database as .SQL file using the mysqldump.exe with the help of the following java code.

Process runProcess = Runtime.getRuntime().exec("C:\\SCM Files\\SQL Backup\\mysqldump.exe -uroot -p123 rr -r\"C:\\SCM Files\\SQL Backup\\RR.sql");


Now I want to restore this same .SQL Backup file to mysql database using java code similar to above on the event of a button clicked.

Thanks a lot :)

So now I tried this ;
Process runProcess = Runtime.getRuntime().exec("C:\\SCM Files\\SQL Backup\\mysqldump.exe -uroot -p123 rr < C:\\SCM Files\\SQL Backup\\RR.sql");

Still it didn't work :/

Answer
Runtime.getRuntime().exec("mysql -u username -ppassword database_name  FILE.sql")

This statement will regenerate database from the file