# Can't restore from mysql dump file

I used mysqldump command to export/dump .sql file with rows like:

String cmd1 = mysqldump + " -h" + host + " -u" + username + " -p" + password + " " + "--compact --no-create-info " + "--where=ID=" + "'5b4ed36d-6152-4bfd-ad06-666f781e8bdc'" + " " + database + " " + "EMPLOYEE" + " " + "--result-file=" + "C:\\employee.sql";


This is the result of above command in a employee.sql file:

INSERT INTO employee VALUES ('Anette','Busch','2014-08-12','admin',' ','FALSE');


Now, I want to import the values from empolyee.sql file using command:

String cmd =  mysql + " --user=" + username + " --password=" + password +  " -e" + " source " + restoreFile;


The problem is I can't execute import command. I'm using the same import command for whole database, that works fine, but not in this case.

Thanks a lot for your guidance.

The problem is that you forgot to put double quotes around the -e parameter

String cmd =  mysql + " --user=" + username + " --password=" + password +  " -e\"" + "source " + restoreFile + "\"";


An alternative would be to redirect the file into the mysql client

String cmd =  mysql + " --user=" + username + " --password=" + password +  " < " + restoreFile;


I also just noticed that you forgot to set the target database

String cmd =  mysql + " --user=" + username + " --password=" + password +  " -D" + mydb + "-e\"" + "source " + restoreFile + "\"";

String cmd =  mysql + " --user=" + username + " --password=" + password +  " -D" + mydb + "  < " + restoreFile;


Give it a Try !!!

• I can't execute "<" in java. Aug 25 '14 at 14:41
• You forgot to set the target database when importing. I updated my answer. Aug 25 '14 at 14:45
• processComplete = runtimeProcess.waitFor(); The program gets stuck in this line. Doesn't return 0, which mean successful import. Aug 25 '14 at 15:05
• Do you have the EMPLOYEE table already in the target database ? Is the target database on the same DB Server ? Aug 25 '14 at 15:21
• Yes! I have it there... Target Database is also on the same DB Server. Aug 25 '14 at 15:44