How to Import export MySQL database from command line

advertisement logo

 

This tip would be useful for those who are either making backup of their remote mysql database or moving their web hosting to their provider.

Here’s how to export mysql DB to SQL file using command-line utility :
mysqldump –user=username –password=1234 –databases your_database –opt –quote-names –complete-insert > example.sql

Here’s how to import the SQL back into mysql database :
mysql –user=username –password=1234 –databases your_database –host=mysql_server host

Don’t forget to add your ip address to the list of allowable host on the remote MySQL server!


Share this post

Tags: , , , , , , , , , ,

Keep updated with the latest posts, be a part of over 1,000 subscribers! : email iconSubscribe to your email

8 smashing comments for this post.

  1. Jadu Saikia Said:

    Nice one. Thanks.

    //Jadu, unstableme.blogspot.com

  2. vps Said:

    I use it nice article thank you

  3. photo sharing Said:

    I’ve also used

    mysql -u username -p databasename > backup.sql

  4. mybands Said:

    I need try this. This is interesting.

  5. ssk sorular? Said:

    mysql -u username -p databasename > backup.sql

    thanks

  6. Colocation Dedicated Voip Said:

    Thanks a useful document

    Dedicated Colocation Voip Datacenter

  7. ranjitha Said:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;

    import java.io.*;
    import java.sql.*;
    import java.util.*;

    class Login
    {
    public static void main(String[]args )
    {
    loginfrm frame=new loginfrm();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    }
    class loginfrm extends JFrame
    {
    public loginfrm()
    {
    setTitle(“translate”);
    setSize(275,100);

    ActionListener listener1=new CommandAction1();
    ActionListener listener2=new CommandAction2();

    panel1=new JPanel();
    panel2=new JPanel();

    JLabel LogLabel = new JLabel(“ENGLISH :”);
    Lname = new JTextField(“”,100);

    JLabel Result = new JLabel(“Result”);
    panel1.add(LogLabel);
    panel1.add(Result);
    panel1.add(Lname);

    add(panel1);

    buttonOK =new JButton(“OK”);
    buttonOK.addActionListener(listener1);;
    panel2.add(buttonOK);

    buttonCancel =new JButton(“CLOSE”);
    buttonCancel.addActionListener(listener2);;
    panel2.add(buttonCancel);

    add(panel1,BorderLayout.NORTH);
    add(panel2,BorderLayout.SOUTH);

    pack();
    }

    private class CommandAction1 implements ActionListener
    {

    public void actionPerformed(ActionEvent ae)
    {
    String lname;

    lname=Lname.getText();

    try
    {
    Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
    connstring=”jdbc:odbc:LOG”;
    conn=DriverManager.getConnection(connstring,”",”");
    stmt=conn.createStatement();
    }
    catch(Exception e)
    {
    System.out.println(“Error in program “+e.toString());
    }
    try
    {
    rs=stmt.executeQuery(“SELECT KANNADA FROM LOGIN where ENGLISH=’”+lname+”‘”);

    while(rs.next())
    {
    System.out.println(rs.getString(1));
    }
    }
    catch(Exception e)
    {
    System.out.println(“Error while trying to display table”+e.toString());
    }
    }
    }
    private class CommandAction2 implements ActionListener
    {
    public void actionPerformed(ActionEvent ae)
    {
    System.exit(0);
    }
    }

    private JPanel panel1,panel2;
    private JLabel LogLabeL;
    private JButton buttonOK,buttonCancel;
    private JTextField Lname;

    String s;
    static Connection conn=null;
    static String connstring, sqlD;
    static Statement stmt;
    static ResultSet rs;
    }

    can you please tel me how to connect mysql to linux fedora10 with the help of this program??

  8. pranav Said:

    very well explained tutorial

    @Ranjitha read javadoc for DeviceManager, it might helpful

Leave a Comment

Subscribe by email

Enter your Email