MariaDB Connector/C++ on Ubuntu 24.04 (Noble Numbat)

MariaDB Connector/C++ is the official C++ client library from MariaDB for connecting C++ applications to MariaDB (and MySQL) servers. It's a modern alternative to the older MySQL++ library and is actively maintained (unlike classic MySQL++).

It provides a JDBC-style API (similar to MySQL Connector/C++ from Oracle) with classes like sql::Driver, sql::Connection, sql::Statement, sql::PreparedStatement, and sql::ResultSet.

  • There is no direct apt package like libmariadbcpp-dev in the standard Ubuntu repositories.
  • Ubuntu ships MariaDB Connector/C (the C library) via packages like:
    • libmariadb3 (runtime)
    • libmariadb-dev (development headers for C)
    • libmariadb-dev-compat (symlinks for MySQL-compatibility builds)
  • The C++ layer (MariaDB Connector/C++) is not packaged in Ubuntu's repos.
  • You must install it manually from MariaDB's binary tarballs (recommended) or build from source.

MariaDB provides pre-built binaries specifically for Ubuntu 24.04 (Noble). Latest stable version as of early 2026 is around 1.1.7.

  1. Install the required base (MariaDB Connector/C) first:
    sudo apt update
    sudo apt install libmariadb-dev libmariadb3
  2. Download MariaDB Connector/C++ from: https://mariadb.com/downloads/connectors/connectors-data-access/cpp-connector
  3. Extract and install (adjust version/path as needed):
    tar -xzf mariadb-connector-cpp-*.tar.gz
    cd mariadb-connector-cpp-*
    sudo cp -r include/mariadbcppconn /usr/include/
    sudo cp lib/mariadb/libmariadbcpp.so* /usr/lib/x86_64-linux-gnu/
    sudo ldconfig
  4. Verify installation with ls commands as shown in the original article.

sudo apt install build-essential cmake libmariadb-dev git
git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git
cd mariadb-connector-cpp
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DWITH_SSL=OPENSSL
make -j$(nproc)
sudo make install

#include <mariadb++/connection.hpp>
#include <iostream>

int main() {
    try {
        mariadb::connection::ptr conn = mariadb::connection::create(
            "tcp://127.0.0.1:3306?user=root&password=yourpass&database=testdb"
        );

        auto stmt = conn->create_statement("SELECT VERSION()");
        auto res = stmt->query();

        if (res->next()) {
            std::cout << "MariaDB version: " << res->get_string(0) << std::endl;
        }
    } catch (const mariadb::exception::base& e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }
    return 0;
}

Compile with: g++ -o test test.cpp -lmariadbcpp -lmariadb

AspectMariaDB Connector/C++MySQL Connector/C++
MaintainerMariaDB CorporationOracle
API styleJDBC-like (sql:: namespace)Same JDBC-like
Ubuntu apt packageNone (manual install)libmysqlcppconn-dev
MySQL 8+ auth supportYesYes
MariaDB-specific featuresBetter/faster integrationFully compatible
Recommended if...Using MariaDB serverUsing official MySQL server

Article content complete. Thanks for reading!