1. Download the JDBC driver on the official website, I downloaded the mysql-connector-java-5.0.8.tar.gz
2. Unzip the downloaded file tar-zxvf mysql-connector-java-5.0.8.tar.gz
3. Put the extracted jar package into the/usr/java/jdk1.7.0/jre/lib/ext directory, and the configuration is complete.
Test procedure:
Package test;
Import java.sql.*;
public class Mysqljava {
public static void Main (string[] arg) {
try {
Class.forName ("Com.mysql.jdbc.Driver"); Load MySQL JDBC driver
String url= "JDBC:MYSQL://127.0.0.1:3306/YHB";//Do not use host IP,YHB is the database name in MySQL
Connection conn=drivermanager.getconnection (URL, user name, password); For example (URL, "root", "123456")
System.out.println ("Connect mysql sucess!");
} catch (Exception e) {
Todo:handle exception
E.printstacktrace ();
System.out.println ("failure!");
}
}
}
If the link succeeds, it will print connect MySQL sucess!
Note: To open the MySQL service first.
64-bit CentOS6.5 under eclipse with Java connection MySQL