Posts Tagged ‘connector/c++’

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!