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.

Results 1 to 6 of 6

Thread: Moving MySql Database from one machine to another machine

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Moving MySql Database from one machine to another machine

    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.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Thumbs up Re: Moving MySql Database from one machine to another machine

    Hello vaishali,

    Try this 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();
            } 
     
        }
    }
    You will also find this link very useful:

    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.

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Moving MySql Database from one machine to another machine

    try sqlyog desktop program: export db as sql batch and import on the other server.

  4. #4
    Junior Member
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Moving MySql Database from one machine to another machine

    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...

  5. The Following User Says Thank You to tpjava For This Useful Post:

    JavaPF (April 21st, 2009)

  6. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Moving MySql Database from one machine to another machine

    Quote Originally Posted by tpjava View Post
    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...
    Thanks for your input tpjava.

    I think the code I submitted above does something similar using mysqldump.
    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.

  7. #6
    Junior Member
    Join Date
    May 2010
    Location
    Kurunegala, SriLanka
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Moving MySql Database from one machine to another machine

    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..............

Similar Threads

  1. Java error "could not create java virtual machine"
    By aubrey4444 in forum Java Theory & Questions
    Replies: 17
    Last Post: October 3rd, 2010, 12:51 PM
  2. Problem in navigation in a txt file with specific direction
    By wendybird79 in forum Collections and Generics
    Replies: 1
    Last Post: May 10th, 2009, 07:54 AM
  3. need help with Vending Machine code...
    By mia_tech in forum Loops & Control Statements
    Replies: 3
    Last Post: April 20th, 2009, 05:24 AM
  4. Replies: 8
    Last Post: February 24th, 2009, 04:04 PM
  5. Replies: 6
    Last Post: November 14th, 2008, 03:09 PM

Tags for this Thread