Installing MySQL Connector/C++ from Source

Before you proceed with the installation from source, check the Connector/C++ downloads page to see whether the driver is available in binary form for your build platform, and whether it works for you. In general, all the pre-compiled binaries are built with the best possible options for all the supported platforms. Installation from the binary package is very straight forward on all platforms - simply unpacking the zip archive in a desired location installs the Connector/C++ driver.


These instructions outline the dependencies and the steps to build and install the Connector/C++ driver on all supported platforms. bash shell was used to show all the examples in this tutorial.

Build-time Dependencies

  • CMake 2.6.2 or later on Microsoft Windows, and version 2.4.2 or later on rest of the supported platforms

    • CMake is a cross-platform build system that generates native build files for your environment.
  • MySQL client programming support

    • Connector/C++ is based on the MySQL C API, and the driver is linked against the MySQL Client Library.
  • GLib 2.2.3 or later on Linux

Install CMake

Check the CMake software downloads page for the pre-compiled binary for your build platform. If the binary is not available, or if you plan to build CMake from a source tree, check Installing CMake page for the instructions to build CMake.

The following example demonstrates the steps involved in building & installing CMake in a non-default location on Solaris operating system. Sun Studio C/C++ compilers were used to build CMake.

# gunzip -c cmake-2.6.3.tar.gz | tar -xvf -
# cd cmake-2.6.3

# export CC=cc
# export CXX=CC

# ./bootstrap --prefix=/export/expts/CMake

# make
# make install

# export PATH=/export/expts/CMake/bin:$PATH

# which cmake

# cmake -version
cmake version 2.6-patch 3

Install MySQL Client Programming Support

MySQL Connector/C++ mandates the installation of MySQL 5.1 [or later] client programming support -- MySQL specific libraries and the header files. Majority of the MySQL Server installation methods on different platforms install the necessary files by default. However if you installed MySQL from RPM files on Linux, be sure that you've installed the developer RPM. The client programs are in the client RPM, but client programming support is in the developer RPM.

If you do not have the MySQL Server installed and if you only need the MySQL Client Library along with the header files, consider installing MySQL Connector/C on the build machine for the required client programming support. MySQL Connector/C is a C client library for client-server communication. It is a standalone replacement for the MySQL Client Library shipped with the MySQL Server. As of this writing, MySQL Connector/C 6.0 is available in the source form as well as the binary form for Solaris, Linux, Windows, FreeBSD, Mac OS X, HP-UX and AIX platforms. MSI installer and a binary zip file without the installer is available for Windows, where as the binary package is available as compressed GNU TAR archive (tar.gz) for the rest of the platforms. You can download the source code and the pre-compiled binary from the Connector/C 6.0 download page. Building the Connector/C driver from the source code is very similar to building the Connector/C++ driver from the source code.

If Connector/C does not fit your requirements, download MySQL, then install.

Add the location of the MySQL Client Library to the search path that the runtime linker uses to find dynamic dependencies. For example, on Solaris OS, use LD_LIBRARY_PATH environment variable to set the runtime linker search path as shown below.


# ls -1 /export/expts/MySQLConnectorC6.0/lib/

# export LD_LIBRARY_PATH=/export/expts/MySQLConnectorC6.0/lib:$LD_LIBRARY_PATH

                                = OR =

MySQL Server

# ls -1 /opt/coolstack/mysql_32bit/lib/mysql/

# export LD_LIBRARY_PATH=/opt/coolstack/mysql_32bit/lib/mysql:$LD_LIBRARY_PATH

Build & Install MySQL Connector/C++

The following step-by-step instructions are applicable to all supported UNIX like platforms. Check MySQL Forge Wiki and MySQL Connector/C++: Guide on building a Windows Client using Visual Studio (for Dummies) pages for the Windows build instructions.

  1. Download the latest version of the MySQL Connector/C++ source tree from

  2. Extract the source files.

    # gunzip -c mysql-connector-c++-1.0.4-beta.tar.gz | tar -xvf -
    # cd mysql-connector-c++-1.0.4-beta
  3. If you are not using the GNU C/C++ compilers, you need to tell the Make build system which compiler to use by setting the environment variables CC and CXX.

    For example, to use Sun Studio C/C++ compilers on Solaris and Linux platforms, set the environment variables CC and CXX as shown below.

    # which cc
    # which CC
    # export CC=cc
    # export CXX=CC
  4. Run CMake, the cross-platform build system, to generate the Makefile. In this step, you can specify the compiler and link-editor options. In addition, you can specify a variety of options like the installation directory, build type - debug or non-debug, location of mysql_config in this step. For all the supported options and the exact syntax, check the CMake Documentation.

    # cmake -DCMAKE_REQUIRED_FLAGS=-xO4 -DCMAKE_INSTALL_PREFIX=/export/expts/MySQLConnectorC++

    On non-Windows systems, CMake tries to locate mysql_config file in the default locations, if the CMake variable MYSQL_CONFIG_EXECUTABLE is not set. If the MySQL Server is installed in a non-default location, set the CMake variable MYSQL_CONFIG_EXECUTABLE.

    # cmake -DMYSQL_CONFIG_EXECUTABLE=/path/to/my/mysql/server/bin/mysql_config [.. other options ..]

    On Windows platform, mysql_config is not available. Hence CMake attempts to retrieve the location of MySQL from the environment variable $ENV{MYSQL_DIR}. If MYSQL_DIR variable is not set, then CMake proceeds to check for MySQL in the following locations: $ENV{ProgramFiles}/MySQL/*/include and $ENV{SystemDrive}/MySQL/*/include.

    To build debug version of the MySQL Connector/C++, set the CMake variable CMAKE_BUILD_TYPE to Debug.

    # cmake -DCMAKE_BUILD_TYPE=Debug [.. other options ..]

    The MySQL Connector/C++ driver is capable of generating debug traces. By default, connector's internal tracing functionality is not available. If you need it, you have to enable the tracing module at compile time using the CMake option, -DMYSQLCPPCONN_TRACE_ENABLE:BOOL=1. The tracing functionality is available with both debug and non-debug builds of the connector, hence it is not required to build debug version of the MySQL Connector/C++ driver in order to use the internal tracing functionality of the connector.

    To enable the tracing module, set the CMake variable MYSQLCPPCONN_TRACE_ENABLE with the type BOOL and the value set to 1.

    # cmake -DMYSQLCPPCONN_TRACE_ENABLE:BOOL=1 [.. other options ..]

    In addition to the internal debug traces, Connector/C++ can also generate debug traces when linked against the debug version of MySQL Client Library. Check Debug Tracing with MySQL Connector/C++ for more details.

    Run cmake -L to check the list of options being used by CMake.

  5. Run make to build the Connector/C++ driver.

    # make
  6. Finally run make with the install option to install the Connector/C++ driver in the designated location.

    # make install
    -- Installing: /export/expts/MySQLConnectorC++/lib/
    -- Installing: /export/expts/MySQLConnectorC++/lib/libmysqlcppconn-static.a
    -- Installing: /export/expts/MySQLConnectorC++/include/mysql_connection.h
    -- Installing: /export/expts/MySQLConnectorC++/include/mysql_driver.h

    If the CMake variable CMAKE_INSTALL_PREFIX was not set during the Makefile generation (step #4), the driver along with the header files will be installed in the default location, /usr/local.