libocimysql is a drop-in replacement for the MySQL / MariaDB C client library (libmysqlclient) that talks to Oracle Database underneath via the Oracle Call Interface (OCI). Applications written against the MySQL C API can be re-linked against, or redirected to, libocimysql and run against Oracle with no source changes to their database calls.
Scope note. Like the (now deprecated) MySQL Client Library for Oracle, from Oracle, this driver does not translate SQL. Your schema and statements must be valid for Oracle (or run through a separate SQL translator). It bridges a subset of the MySQL client API and data types, not the SQL dialect. If you desire translation, this is Apache licensed, and you're free to add it yourself!
The first version of this library began in the mid-2000s as a lowly, function-interposing MySQL C API call tracer, and there are still remnants of this to be removed. Given most scripting language MySQL interfaces at the time were based on the C client, the library was transformed into a drop-in replacement bridge for MySQL-to-ODBC, allowing many simple apps written for MySQL to run against most other databases unchanged; the main caveat being mysql_insert_id(), which was often a killer. Later, the ODBC driver wasn't found to be as optimal for Oracle as a consulting client wanted, so another round of modifications were made, replacing ODBC with OCI. About a year or so after, Oracle created their own, nearly identical, MySQL Client Library for Oracle (liboramysql). This was nice, as it validated our concept. For the most part, with minor exceptions, both libraries are comparable in functionality; there's only so many ways to make Oracle emulate MySQL at the client level. One plus of Oracle's, though, was it had a Windows port - and MySQL was super popular on Windows. We had neither the desire nor need to build that.
While the original library was used in production, this open source release was passed through Claude for documentation and clean-up, and has not yet been used in production. Use it at your own risk!
| Document | Contents |
|---|---|
docs/COVERAGE.md |
MySQL C client library exported functions, classified (OCI / delegate / accessor / no-op) with status. |
docs/CONFIGURATION.md |
The libocimysql.ini configuration file and every option (e.g. date_mapping). |
The library builds against an Oracle Instant Client SDK (for oci.h / libclntsh) and MySQL or MariaDB client headers. OCI headers are never vendored in this repository; they are located at configure time or downloaded into the build container.
No local Oracle toolchain required — everything runs in containers, including an Oracle Database Free instance to test against:
make help # list all developer targets
make docker-test # build the library + run the smoke test against OracleThe build image downloads the Instant Client (Basic + SDK) at build time; the oracle service uses gvenzl/oracle-free. On Apple Silicon the images run under x86-64 emulation.
./autogen.sh
./configure --with-oci=/path/to/instantclient # or set OCI_HOME / ORACLE_HOME
makeconfigure locates the OCI SDK (--with-oci, OCI_HOME, or ORACLE_HOME) and the MySQL/MariaDB headers (--with-mysql-config, else mysql_config / mariadb_config on PATH).
The library installs under a version- and target-qualified name so multiple client-ABI builds can coexist:
libocimysql-<LIBOCIMYSQL_VER>-<MYSQL_VER>-<ARCH>-<RELEASE>.so
The MySQL host argument carries an Oracle Easy Connect string; db, port, unix_socket, and client_flag are ignored (Oracle takes the service in the connect string):
MYSQL *c = mysql_init(NULL);
mysql_real_connect(c, "dbhost:1521/service_name", "user", "password",
NULL, 0, NULL, 0);
mysql_query(c, "insert into mytable values (1, 2)");
mysql_close(c);Runtime behavior is tunable via an INI file pointed to by the LIBOCIMYSQL_INI environment variable. For example, to report Oracle DATE columns as MYSQL_TYPE_DATETIME instead of the default MYSQL_TYPE_DATE:
[default]
date_mapping = datetimeSee docs/CONFIGURATION.md for all options.
Apache 2.0