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.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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: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
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
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...
JavaPF (April 21st, 2009)
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
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..............