HOWTO: MySQL Connector/C++ on Mac OS X

Excited with the release of the MySQL Connector/C++, I thought I’d get it going on Mac OS X.

You’ll first hit the problem that Mac OS X doesn’t come with CMake. So you’ll have to download it from the site – there’s a warning there that the .dmg installer only works for Tiger, but I ran it on Leopard, and its just fine. Don’t forget to allow it to create links in /usr/bin for ease of use.

After that, you will need to install glib. But to get glib going, you need some dependencies:

Installing them is simple: untar (tar -zxvpf package.tar.gz), ./configure, make, then a sudo make install.

Now, the README file or the instructions on the wiki will just work. I have several MySQL installations, so I preferred to specify what cmake found. I did this by:
cmake -D MYSQL_DIR:PATH=/usr/local/mysql/ -D GLIB_DIR:PATH=/usr/local/lib/glib-2.0/ .

Then a simple make, and you can go on and try the examples, in examples/. Try the connect application to make sure things are working. You will probably run into a snag though:

luna:examples ccharles$ ./connect
Connector/C++ connect basic usage example..

ERR: MySQL_DbcException in /Users/ccharles/code/mysql_connector_cpp_1_0_0_preview/examples/connect.cpp((function n/a)) on line 159
ERR: Cannot connect (MySQL error code: 0 )

Take a look at examples/examples.h, and look at the connection properties. It uses the test database, on localhost (, standard port 3306, user is root, and the default password set there is root too. This may not be the commonest setting, so don’t hesitate to change the password or leave it blank (ala a default install), and rerun make. The sample applications will now work :)

Congratulations to Andrey, Ulf, and the rest of the connectors team in getting this going!


  1. andrey says:

    GLIB is not hard-requirement. If there it will be used for building a component called driver manager, which, however, we don’t use. It can be used if there are more than one drivers, for example a PGSQL Driver. Then one uses the DriverManager and glib loads the dll that contains the driver. glib is used for platform-agnostic loading of dll/so. We compile on (Open)Solaris without GLIB and everything runs fine. If GLIB is not present CMake won’t configure the driver manager.

  2. andrey says:

    One more thing. There is test/ directory with a static_test.cpp . When it gets built one can use it to verify whether the Connector has problems. Default values are root/root . If you need other values pass them in the same order to the binary
    > ./static_test 3305 root pwd

    CMake either needs MYSQL_DIR, which is actually for Windows, where there is no mysql_config, or just pass
    -D MYSQL_CONFIG_EXECUTABLE=/path/to/mysql_config

    If MYSQL_DIR is there or in the ENV it will be used to find mysql_config.

  3. […] – bookmarked by 3 members originally found by KIRBYMASTERXL on 2008-09-24 HOWTO: MySQL Connector/C++ on Mac OS X – bookmarked by […]

  4. David says:

    Outstanding. Thanks for including the clue on the default root password error. A practically effortless install. You rock!

  5. David says:

    Outstanding. Thanks for including the clue on the default root password error. A practically effortless install. You rock!