MySQL Connector/J 5.1 Developer Guide
To just get MySQL Connector/J up and running on your system, install Connector/J using a standard binary release distribution. Instructions in this section is only for users who, for various reasons, want to compile Connector/J from source.
The requirements and steps for installing from source Connector/J 5.1.37 or later, 5.1.34 to 5.1.36, and 5.1.33 or earlier are different; check the section below that is relevant for the version you want.
Installing Connector/J 5.1.37 or later from source. To install MySQL Connector/J from its source tree on GitHub, you need to have the following software on your system:
A Git client, to check out the sources from our GitHub repository (available from http://git-scm.com/downloads).
Apache Ant version 1.8.2 or newer (available from http://ant.apache.org/).
JDK 1.8.x AND JDK 1.5.x.
JRE 1.6.x (optional)
The following third-party libraries:
JUnit 4.12 (junit-4.12.jar
,
available from
https://github.com/junit-team/junit/wiki/Download-and-Install).
C3P0 0.9.1 or newer (both
c3p0-0.9.1.x.jar
and
c3p0-0.9.1.x.src.zip
, available
from
https://sourceforge.net/projects/c3p0/).
JBoss common JDBC wrapper 3.2.3 or newer
(jboss-common-jdbc-wrapper-3.2.3.jar
,
available from, for example, the Maven Central
Repository at
http://central.maven.org/maven2/jboss/jboss-common-jdbc-wrapper/).
Simple Logging Facade API 1.6.1 or newer
(slf4j-api-1.6.1.jar
, available
from
https://www.slf4j.org/download.html).
The required .jar
files from the
Hibernate ORM 4.1 or 4.2 Final release bundle, which is
available at
http://sourceforge.net/projects/hibernate/files/hibernate4/.
To check out and compile MySQL Connector/J, follow these steps:
Check out the code from the source code repository for MySQL Connector/J located on GitHub at https://github.com/mysql/mysql-connector-j; for the latest release of the Connector/J 5.1 series, use the following command:
shell> git clone https://github.com/mysql/mysql-connector-j.git
To check out a release other than the latest one, use the
--branch
option to specify the revision tag
for it:
shell> git clone --branch 5.1 https://github.com/mysql/mysql-connector-j.git
Under the current directory, the commands create a
mysql-connector-j
subdirectory , which
contains the code you want.
Make sure that you have both JDK 1.8.x AND JDK 1.5.x installed. You need both JDKs because besides supporting JDBC from 4.0 to 4.2, Connector/J 5.1 also supports JDBC 3.0, which is an older version and requires the older JDK 1.5.x.
Consider also having JRE 1.6.x installed. This is optional:
if JRE 1.6.x is not available or not supplied to Ant with
the property com.mysql.jdbc.java6.rtjar
,
the Java 8 bootstrap classes will be used. A warning will be
returned, saying that the bootstrap class path was not set
with the option to compile sources written for Java 6.
Place the required junit.jar
file in a
separate directory—for example,
/home/username/ant-extralibs
.
In the same directory for extra libraries described in the
last step, create a directory named
hibernate4
, and put under it all the
.jar
files you can find under the
/lib/required/
folder in the Hibernate
ORM 4 Final release bundle.
Change your current working directory to the
mysql-connector-j
directory created in
step 1 above.
In the directory, create a file named
build.properties
to indicate to Ant the
locations of the root directories for your JDK 1.8.x and JDK
1.5.x installations, the location of the
rt.jar
of your JRE 1.6.x (optional),
and the location of the extra libraries. The file should
contain the following property settings, with the
“path_to_*
” parts
replaced by the appropriate filepaths:
com.mysql.jdbc.jdk8=path_to_jdk_1.8
com.mysql.jdbc.jdk5=path_to_jdk_1.5
com.mysql.jdbc.java6.rtjar=path_to_rt.jar_under_jre_1.6
/rt.jar com.mysql.jdbc.extra.libs=path_to_folder_for_extra_libraries
Alternatively, you can set the values of those properties
through the Ant -D
options.
Issue the following command to compile the driver and create
a .jar
file for Connector/J:
shell> ant dist
This creates a build
directory in the
current directory, where all the build output goes. A
directory is created under the build
directory, whose name includes the version number of the
release you are building. That directory contains the
sources, the compiled .class
files, and
a .jar
file for deployment. For more
information and other possible targets, including those that
create a fully packaged distribution, issue the following
command:
shell> ant -projecthelp
Install the newly created .jar
file for
the JDBC driver as you would install a binary
.jar
file you download from MySQL by
following the instructions given in
Section 3.2, “Installing the Driver and Configuring the CLASSPATH
”.
Note that a package containing both the binary and source code for Connector/J 5.1 can also be downloaded from the Connector/J Download page.
Installing Connector/J 5.1.34 to 5.1.36 from source. To install MySQL Connector/J 5.1.34 to 5.1.36 from the Connector/J source tree on GitHub, make sure that you have the following software on your system:
A Git client, to check out the sources from our GitHub repository (available from http://git-scm.com/downloads).
Apache Ant version 1.8.2 or newer (available from http://ant.apache.org/).
JDK 1.6.x AND JDK 1.5.x.
JUnit libraries (available from https://github.com/junit-team/junit/wiki/Download-and-Install).
The required .jar
files from the
Hibernate ORM 4.1 or 4.2 Final release bundle, which is
available at
http://sourceforge.net/projects/hibernate/files/hibernate4/.
To check out and compile MySQL Connector/J, follow these steps:
Check out the code from the source code repository for MySQL
Connector/J located on GitHub at
https://github.com/mysql/mysql-connector-j,
using the --branch
option to specify the
revision tag for release 5.1.xx
:
shell> git clone --branch 5.1.xx
https://github.com/mysql/mysql-connector-j.git
Under the current directory, the commands create a
mysql-connector-j
subdirectory , which
contains the code you want.
Make sure that you have both JDK 1.6.x AND JDK 1.5.x installed. You need both JDKs because Connector/J 5.1 supports both JDBC 3.0 (which has existed prior to JDK 1.6.x) and JDBC 4.0.
Place the required junit.jar
file in a
separate directory—for example,
/home/username/ant-extralibs
.
In the same directory for extra libraries described in the
last step, create a directory named
hibernate4
, and put under it all the
.jar
files you can find under the
/lib/required/
folder in the Hibernate
ORM 4 Final release bundle.
Change your current working directory to the
mysql-connector-j
directory created in
step 1 above.
In the directory, create a file named
build.properties
to indicate to Ant the
locations of the root directories for your JDK 1.5.x and JDK
1.6.x installations, as well as the location of the extra
libraries. The file should contain the following property
settings, with the
“path_to_*
” parts
replaced by the appropriate filepaths:
com.mysql.jdbc.jdk5=path_to_jdk_1.5
com.mysql.jdbc.jdk6=path_to_jdk_1.6
com.mysql.jdbc.extra.libs=path_to_folder_for_extra_libraries
Alternatively, you can set the values of those properties
through the Ant -D
options.
Issue the following command to compile the driver and create
a .jar
file for Connector/J:
shell> ant dist
This creates a build
directory in the
current directory, where all the build output goes. A
directory is created under the build
directory, whose name includes the version number of the
release you are building. That directory contains the
sources, the compiled .class
files, and
a .jar
file for deployment. For more
information and other possible targets, including those that
create a fully packaged distribution, issue the following
command:
shell> ant -projecthelp
Install the newly created .jar
file for
the JDBC driver as you would install a binary
.jar
file you download from MySQL by
following the instructions given in
Section 3.2, “Installing the Driver and Configuring the CLASSPATH
”.
Installing Connector/J 5.1.33 or earlier from the source tree. To install MySQL Connector/J 5.1.33 or earlier from the Connector/J source tree on GitHub, make sure that you have the following software on your system:
A Git client, to check out the source code from our GitHub repository (available from http://git-scm.com/downloads).
Apache Ant version 1.7 or newer (available from http://ant.apache.org/).
JDK 1.6.x AND JDK 1.5.x. Refer to Section 2.2, “Java Versions Supported” for the version of Java you need to build or run any Connector/J release.
The Ant Contrib (version 1.03b is available from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/) and JUnit (available from https://github.com/junit-team/junit/wiki/Download-and-Install) libraries.
The required .jar
files from the
Hibernate ORM 4.1 or 4.2 Final release bundle, which is
available at
http://sourceforge.net/projects/hibernate/files/hibernate4/.
To check out and compile a specific branch of MySQL Connector/J, follow these steps:
Check out the code from the source code repository for MySQL
Connector/J located on GitHub at
https://github.com/mysql/mysql-connector-j,
using the --branch
option to specify the
revision tag for release 5.1.xx
:
shell> git clone --branch 5.1.xx
https://github.com/mysql/mysql-connector-j.git
Under the current directory, the commands create a
mysql-connector-j
subdirectory , which
contains the code you want.
To build Connector/J 5.1, make sure that you have both JDK
1.6.x AND JDK 1.5.x installed. You need
both JDKs because Connector/J 5.1 supports both JDBC 3.0
(which has existed prior to JDK 1.6.x) and JDBC 4.0. Set
your JAVA_HOME
environment variable to
the path to the JDK 1.5.x installation.
Place the required ant-contrib.jar
file
(in exactly that name, without the version number in it;
rename the jar
file if needed) and
junit.jar
file in a separate
directory—for example,
/home/username/ant-extralibs
.
In the same directory for extra libraries described in the
last step, create a directory named
hibernate4
, and put under it all the
.jar
files you can find under the
/lib/required/
folder in the Hibernate
ORM 4 Final release bundle.
Change your current working directory to the
mysql-connector-j
directory created in
step 1 above.
In the directory, create a file named
build.properties
to indicate to Ant the
locations of the Javac and rt.jar
of
your JDK 1.6.x, as well as the location of the extra
libraries. The file should contain the following property
settings, with the
“path_to_*
” parts
replaced by the appropriate filepaths:
com.mysql.jdbc.java6.javac=path_to_javac_1.6
/javac com.mysql.jdbc.java6.rtjar=path_to_rt.jar_under_jdk_1.6
/rt.jar com.mysql.jdbc.extra.libs=path_to_folder_for_extra_libraries
Alternatively, you can set the values of those properties
through the Ant -D
options.
Issue the following command to compile the driver and create
a .jar
file for Connector/J:
shell> ant dist
This creates a build
directory in the
current directory, where all the build output goes. A
directory is created under the build
directory, whose name includes the version number of the
release you are building. That directory contains the
sources, the compiled .class
files, and
a .jar
file for deployment. For more
information and other possible targets, including those that
create a fully packaged distribution, issue the following
command:
shell> ant -projecthelp
Install the newly created .jar
file for
the JDBC driver as you would install a binary
.jar
file you download from MySQL by
following the instructions given in
Section 3.2, “Installing the Driver and Configuring the CLASSPATH
”.