How to Import export MySQL database from command line

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!

9 Replies to “How to Import export MySQL database from command line”

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

Comments are closed.