Hi,
I am working on a project which uses java and Mysql as a database on Windows XP.My problem is how to keep backup of database or how to copy database from one machine to the other?
Thanx.
Printable View
Hi,
I am working on a project which uses java and Mysql as a database on Windows XP.My problem is how to keep backup of database or how to copy database from one machine to the other?
Thanx.
Hello vaishali,
Try this code:
You will also find this link very useful:Code :import java.io.*; public class sqlBackup { public static void main(String[] args) { //Location of the backup File test = new File("C:/mysql-5.0.27-win32/bin/backup.sql"); FileWriter fw = null; try { fw = new FileWriter(test); Runtime rt = Runtime.getRuntime(); //start output backup - change bjse to db name Process child = rt.exec("mysqldump -u root bjse"); InputStream in = child.getInputStream(); InputStreamReader xx = new InputStreamReader(in, "utf8"); char[] chars = new char[1]; int ibyte = 0; while ((ibyte = xx.read(chars)) > 0) { fw.write(chars); } fw.close(); System.out.println("OK! Completed"); }catch(Exception e) { e.printStackTrace(); } } }
HowTo For Idiots: Backup MySQL Database From Java Part 1
try sqlyog desktop program: export db as sql batch and import on the other server.
You can use the mysql command mysqldump to copy contents of your database from the command prompt.
I know its not java code but if you do it programatically you will first have to install java etc...
Mysqldump –u root –all-databases > tmp.sql will save it to a folder where you can then use the reverse:
Mysqldump –u root –all-databases < tmp.sql to pull it back in on the new machine.
Hope it helps...
Hi Vaishaly,
Simply you go to Mysql administrater window. Then click on Backup. It will ask for project name. After giving project name you will can add backup to a file. then when you want to restore, goto restore button and restore it. Try it..............