7/14/2012

How to copy Mysql databse from one Computer to another / backup database using mysqldump

             We can take backup of MySQL database by using musqldump.
             We can transfer a MySQL database from one PC to another PC using mysqldump command. We have to create dump file of database to transfer database from one PC to another PC.
          MySQL databse is not portable database i.e. we cannot transfer it from one PC to another PC by copying and pasting it. We can use following method to transfer database.

1.   Creating a dumpfile from database/ Taking backup of MySQL database:
-  Open command prompt.
-  Execute following commands to change directory
>c:  “press enter”
>cd  program files/MySQL/MySQL Server 5.1/ bin “press enter”
>mysqldump -u root  -p databse_name > database_name.sql  “press enter”
  Enter password: password of MySQL

Copy sql file and paste it in PC where you want to transfer database.

.          2. Dumping sql file into database:-
          - Open MySQL  command line client command prompt.
          - Execute following command to create database.
                 >create database database_name;  “press enter”
Database name is must as that of your database _name.
Copy that sql file into location “c:/program files/MySQL/MySQL Server 5.1/bin”

          - Now open command prompt and execute following commands.
                >C: “press enter”
                >cd program files/MySQL/MySQL Server5.1/bin “press enter”
                >mysql –u root –p database_name < database_name.sql “press enter”

           Your database is created on PC.
           Now in MySQL command prompt check your database.  

7/11/2012

Java database connectivity with MySQL Server Databse

easywayprogramming.com java database connectivity with mysql database

Before executing following program follow instruction in following link:
database connectivity instruction 

my_sql.java
import java.sql.*;
import java.io.*;

public class my_sql
{
    public my_sql()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            System.out.println("Driver loaded!!!!!!!!!");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost/employee","root","ashu");
            System.out.println("connection made!!!!!!!!!");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select *from emp");

            while (rs.next())
            {
                 System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t\t\t"+rs.getString(3)+"\t\t\t"+rs.getString(4));
            } //end while

            con.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

       public static void main(String[] args)
    {
        new my_sql();
    }
}


click here: Back to Tricks/Solution