MySQL Blog Archive
For the latest blogs go to blogs.oracle.com/mysql
How to build MySQL 8.0 C API (libmysqlclient)

If you write C applications that need to connect to MySQL, you can use the MySQL C API aka libmysqlclient. The MySQL C API replaces the outdated MySQL-Connector-C.

If you want to use MySQL 8.0 as a Document Store with the X Protocol, you need then to use MySQL Connector/C++ 8.0.

Some have asked how to compile only the MySQL C API.

Compiling only libmysqlclient

As the FAQ stipulates it, it’s not possible to only build the library. However, as mentioned in the documentation, it’s possible to reduce the amount of compiled products with some cmake options.

You still need to get the full source tree (from GitHub for example) and bypass the compilation of the server.

~ $ mkdir workspace
~ $ cd workspace
~workspace $ git clone https://github.com/mysql/mysql-server.git
~workspace $ mkdir mysql-server-bin-debug
~workspace $ cd mysql-server-bin-debug
~workspace/mysql-server-bin-debug $ cmake -DWITHOUT_SERVER=ON \
                                    -DDOWNLOAD_BOOST=1 \
                                    -DWITH_BOOST=../mysql-server/downloads/ \
                                    -DWITH_UNIT_TESTS=OFF ../mysql-server
~workspace/mysql-server-bin-debug $ make -j 8

On my laptop, this command took 2m24sec

 

Now you have built the client line tools and also libmysqlclient:

libmysqlclient.so

If you want a debug version of the lib, you just need to add -DWITH_DEBUG=1 to the cmake command.

Conclusion

Following the process outlined in this blog post, you will see that it takes a couple of minutes to build the client line tools and also libmysqlclient. You are required to download the complete source tree, and build some extra command line tools, but the process is fast.

My colleague Joro has added some very interesting comments to this bug that I recommend you read for even more information.