Reply from Amol_Bhave on Jan 17 at 2:51 PM try this to back up specific table from database: Process run = rt.exec("C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe -uroot -pPassword DBName tableName -rD:/DBBackup/backUp.sql"); or to back up entire database then Process run = rt.exec("C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe -uUsername -pPassword DBName -rD:/DBBackup/backUp.sql"); You can also use: /* * Please note the BUFFER variable, you may customized for your need. * Just remember, the bigger value, consumes more heaps but decrease loops. * The smaller value, consumes less heaps but increase loops. * / Process run = rt.exec("C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe --host=localhost --port=3306 --user=root --password=Password DBName Tablename-its is optional"); final int BUFFER = 104857; FileOutputStream fos = null; BufferedOutputStream bos = null; InputStream in = run.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuffer temp = new StringBuffer(); int count; char[] cbuf = new char[BUFFER]; while ((count = br.read(cbuf, 0, BUFFER)) != -1) temp.append(cbuf, 0, count); br.close(); in.close(); //Writing to the sql file byte[] data = temp.toString().getBytes(); File sqlDump = new File("D:/DBBackup/data.sql"); fos = new FileOutputStream(sqlDump); bos = new BufferedOutputStream(fos); bos.write(data); fos.close(); bos.close();*/
| | | ---------------Original Message--------------- From: Umaimath Sent: Tuesday, November 06, 2007 12:15 AM Subject: Database restore using mysqldump in java Hii... I was trying to take mysql database backup using java. While using normal mysqldump command there was a problem with ">" symbol.Soi suggested to use "-r" instead of the redirect symbol,like *mysqldump -uUser -pPass test -rbackup.sql * instead of *mysqldump -uUser -pPass test >backup.sql* Then it was working fine. My problem is that i want to know the corresponding option for "<" symbol. That is i want to restore the database. *mysqldump -uUser -pPass test < backup.sql * It is not working. The code is as below. import java.util.*; import java.io.*; public class TestSql { /** Creates a new instance of TestSql */ public TestSql() { } /** * @param args the command line arguments */ public static void main(String[] args) { try { Runtime rt =Runtime.getRuntime(); rt.exec("mysqldump -uUser -pPass test < backup.sql"); }catch(Exception e){ e.printStackTrace(); } // TODO code application logic here } } Please help me, thank you, Umaimath | | Reply to this email to post your response. __.____._ | _.____.__ |
No comments:
Post a Comment