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:

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:

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:

Note that a package containing both the binary and source code
for Connector/J 5.1 can also be found at
Connector/J 5.1 Download

Installing Connector/J 5.1.33 or earlier from the development source
tree.
To install MySQL Connector/J 5.1.33 or earlier from the
development source tree, make sure that you have the following
software on your system:

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:

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:

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: