I know this question has been addressed many times on the site and on the web in general but I am having issues none the less.
I'm using MySql Server 5.0 on a Windows 7 box (though I have working copys of the progrm in question on an xp) with Netbeans 7.0 (and/or eclipse when needed) and 1.6 java.
I have a backup routine using this string ->
String xCommand =
"mysqldump -u username -ppassword dbName -r mySqlBackupFile.sql";
in this code ->
int pComplete = 1;
try{
Process rtProcess = Runtime.getRuntime().exec(xCommand);
pComplete = runtimeProcess.waitFor();
}
catch(Exception e) {
// (I have my own error reporting here)
}
etc... and it all works fine. A backup is created successfully. Great. I've verified that the file is a valid sql import script.
So now I need to have a routine to restore using java. I have tried multiple (+20) solutions to the 'restore mysql db' questions as found on this site and others. My latest incarnation is ->
String xCommand =
"mysql -u username -ppassword dbName < mySqlBackupFile.sql";
None of them have worked. All have similar strings, some say to use 'source' instead of '<', some have various flags ('-r') in the string, etc.
(I had similar problems getting the export to work as well and finally hit upon a solution, almost by accident, that actually worked. Eureka.)
So, here's (finally) my question (besides a working restore string);
Why is it that there are so many working solutions to this issue? In every case there is someone who says 'Great! Worked for me!' but then others (like me) that it didn't work for. And this is regardless of the actual solution. That is, it seems that the actual working backup/restore solutions are extremely platform/operating system/java version/sql version etc dependent and differ greatly.
Is there perhaps some definitive guide somewhere that this information resides?
Since the whole purpose of using java in the first place is, in many cases, the platform independent nature of it, it makes sense to really know what works and what doesn't on what systems and configurations.
Thanks in advance, Jeff
I've actually solved my own issue for the time being with this solution -> https://stackoverflow.com/questions/872494/restore-mysql-from-cmd-line-using-java-environment] ]1 But now I'm getting an issue where the db backup process only works when run from netbeans. Won't work from standalone jar. The restore does work ok however. (the rest of the program works fine as well).
hmm...
sourceis only possible from within the MySQL CLI client (mysql). I never used the-roption to import a database. What you have posted seems pretty normal and should work. If I remember right, the username should be written after the-uoption without using a space, as you had done for the password. Alternatively you may use the parameter--user=username. Try to execute this command manually (i.e. without using JAVA) and see if there are error messages.