0

I backup my MySQL databse to a specific folder, say, d:\backup\ by a webpage. The backup goes without issues, but I am not able to restore it using the following command.

Runtime.getRuntime().exec("mysql -u root -p root sgapp <  D:/backup/bkup.sql");

What is the cause and how can I solve this?

1

2 Answers 2

1
 Runtime.getRuntime().exec("mysql -u USERNAME -pPASSWORD DBNAME <  D:/backup/bkup.sql");

Mind the lack of gap between -p and password string.

Sign up to request clarification or add additional context in comments.

4 Comments

@pheonix4eva -- that was an obvious error. But, I think you should also include the stack trace of the error that you getting when you try from JSP. That will help to dig any deeper.
i tried try { runtime.exec("mysql -uroot -proot dd < D:/backup/bkup.sql"); } catch (IOException ex) { ex.printStackTrace(); } but i get no error
@Nishant - big mistake - if you are going to use redirection, you have to exec via cmd.exe ... I think.
@Stephen C I was wondering the same, but can't do a quick POC right now. :) our jobs.
1

That works for me:

 Runtime.getRuntime().exec("cmd /c start mysqldump -u root -ptestpsw workone -rscript_name.sql");

use -rfilename.sql instead of redirect < . Maybe it works for you too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.