Documentation Home
MySQL Connector/C++ 1.1 Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 285.1Kb
PDF (A4) - 286.0Kb

MySQL Connector/C++ 1.1 Developer Guide  /  Installing Connector/C++ from Source  /  Installing Connector/C++ from Source on Unix and Unix-Like Systems

4.3 Installing Connector/C++ from Source on Unix and Unix-Like Systems

To install Connector/C++ from source, verify that your system satisfies the requirements outlined in Section 4.1, “Source Installation System Prerequisites”.

  1. Change location to the top-level directory of your Connector/C++ source distribution, then run CMake to build a Makefile:

    cmake .

    To use configuration values different from the defaults, use the options described at Section 4.6, “Connector/C++ Source-Configuration Options”. For example, to specify the installation location explicitly, use the CMAKE_INSTALL_PREFIX option:


    CMake checks to see whether the MYSQL_CONFIG_EXECUTABLE CMake option is set. If not, CMake tries to locate mysql_config in the default locations.

  2. Use make to build Connector/C++. First make sure you have a clean build, then build the connector:

    make clean

    If all goes well, you will find the Connector/C++ library in the driver directory.

  3. Install the header and library files:

    make install

    Unless you have changed the installation location in the configuration step by specifying the CMAKE_INSTALL_PREFIX CMake option, make install copies the header files to the directory /usr/local/include. The mysql_connection.h and mysql_driver.h header files are copied.

    Again, unless you have specified otherwise, make install copies the library files to /usr/local/lib. The files copied are the dynamic library, and the static library libmysqlcppconn-static.a. The dynamic library file name extension might differ on your system (for example, .dylib on macOS).

After installing Connector/C++, you can carry out a quick test to check the installation. To do this, compile and run one of the example programs, such as examples/standalone_example.cpp. This example is discussed in more detail later, but for now, you can use it to test whether the connector has been correctly installed. This procedure assumes availability of a working MySQL server to which you can connect. It also assumes header and library locations of /usr/local/include and /usr/local/lib, respectively; adjust these as necessary for your system.

  1. Compile the example program. To do this, change location to the examples directory and enter this command:

    g++ -o test_install \
      -I/usr/local/include -I/usr/local/include/cppconn \
      -Wl,-Bdynamic standalone_example.cpp -lmysqlcppconn
  2. Make sure the dynamic library which is used in this case can be found at runtime:

    export LD_LIBRARY_PATH=/usr/local/lib

    On macOS, try this:

    export DYLD_LIBRARY_PATH=/usr/local/lib

    It may also be necessary to run ldconfig or equivalent utility.

  3. Now run the program to test your installation, substituting the appropriate host, user, password, and database arguments for your system:

    ./test_install localhost root password database

    You should see output similar to the following:

    Connector/C++ standalone program example...
    ... running 'SELECT 'Welcome to Connector/C++' AS _message'
    ... MySQL replies: Welcome to Connector/C++
    ... say it again, MySQL
    ....MySQL replies: Welcome to Connector/C++
    ... find more at