MariaDB Connector/C API Functions
Explore API functions for MariaDB Connector/C. This section provides detailed documentation on functions for connecting, querying, and managing data, enabling robust C applications for MariaDB.
The MariaDB Connector/C API provides functions for establishing connections, executing statements, retrieving and navigating result sets, managing transactions, and configuring connection options, plugins, and metadata.
Function Overview
Immediately aborts a connection by making all subsequent read/write operations fail, without freeing the MYSQL structure or closing communication channels.
Connect to a database server using a connection string.
Checks whether the client is currently connected to a MariaDB or MySQL server.
Converts a string to a different character set.
Returns extended metadata for pluggable field types such as JSON and GEOMETRY.
Retrieves generic or connection-related information.
Retrieves generic or connection-specific information from a MariaDB Connector/C handle, accepting a value-type enum and a pointer to store the result.
Attempts to re-establish a dropped MariaDB Connector/C connection using the original credentials, and requires the MYSQL_OPT_RECONNECT option to be set.
Returns the number of rows affected by the last INSERT, UPDATE, DELETE, or REPLACE statement executed on a MariaDB Connector/C connection.
Enables or disables autocommit mode for the current database connection, returning zero on success or nonzero on failure.
Changes the authenticated user and default database on an existing connection, resetting session state including transactions, temporary tables, and locks.
Returns the name of the default client character set for a specified MariaDB Connector/C connection.
Returns a handle to an already-loaded client plugin of the given name and type.
Terminates an open database connection and releases the memory allocated for the MYSQL handle.
Commits the current transaction on a MariaDB Connector/C connection, returning zero on success without affecting autocommit mode.
Moves the result set pointer to an arbitrary row offset in a buffered result set obtained via mysql_store_result, enabling random row access.
Enables debug output for a MariaDB Connector/C client using the DBUG library, accepting a colon-separated control string to configure trace and logging options.
Instructs a MariaDB server to write connection status information to the error log, and requires the SUPER privilege for the current user.
Determines whether the final row in a result set has already been retrieved. (Deprecated.)
Returns the numeric error code from the most recent MariaDB Connector/C function call, or zero if no error occurred.
Returns the error message string for the most recent failed MariaDB Connector/C function call, or an empty string if no error occurred.
Encodes a string using the default character set for safe use in SQL statements. Deprecated — use mysql_real_escape_string instead.
Returns the definition of one result set column as a MYSQL_FIELD pointer; call it repeatedly to iterate over all columns in the result set.
Returns a MYSQL_FIELD pointer for a specific column in a result set, identified by its zero-based field number.
Returns all column definitions for a MariaDB result set as an array of MYSQL_FIELD structures, one entry per column.
Returns an array of byte lengths for each column in the current row of a MariaDB result set, valid only after mysql_fetch_row is called.
Retrieves the next row from a MariaDB result set as an array of char pointers, returning NULL when no more rows are available.
Returns the number of columns in the most recent query result for a MariaDB connection, useful for checking whether a result set is available.
Sets the field cursor to a given column offset in a MariaDB result set, controlling which field mysql_fetch_field returns next.
Retrieves the current field cursor position in a result set, which can be passed to mysql_field_seek to restore that position.
Releases the memory allocated for a MariaDB result set; row values obtained from prior mysql_fetch_row calls become invalid after this call.
Populates a MY_CHARSET_INFO structure with details about the current default character set for a MariaDB Connector/C connection.
Retrieves the client library version as a string; use mysql_get_client_version for the equivalent numeric value.
Retrieves the client library version as an unsigned long; use mysql_get_client_info for the string representation.
Returns a string describing the connection type and server hostname for a MariaDB Connector/C connection, or NULL if invalid.
Retrieves the current value of a connection option previously set with mysql_optionsv, supporting boolean, integer, string, and miscellaneous option types.
Returns the protocol version number used for a MariaDB Connector/C connection; versions 9 and below are not supported.
Retrieves the connected server version string; use mysql_get_server_version for the equivalent numeric representation.
Retrieves the server version as an unsigned long; use mysql_get_server_info for the equivalent string representation.
Returns the name of the TLS cipher in use for a MariaDB Connector/C connection, or NULL for non-TLS connections.
Retrieves the timeout value configured for asynchronous operations, in seconds.
Retrieves the timeout value configured for asynchronous operations, in milliseconds.
Converts a binary buffer to a hex-encoded string for safe embedding in SQL; the output buffer must be at least 2*length+1 bytes.
Returns a string with summary statistics about the last executed query, covering INSERT, UPDATE, ALTER TABLE, and LOAD DATA operations; returns NULL for SELECT.
Allocates and initializes a MYSQL structure for use with mysql_real_connect, and also initializes the thread subsystem if not already done.
Returns the AUTO_INCREMENT value generated by the last INSERT or UPDATE statement on a MariaDB connection, or zero if no such value was produced.
Requests the MariaDB server to terminate the thread with the given process ID; use mysql_thread_id to obtain the ID of the current connection.
Loads a client plugin of the given name and type from the client plugin directory.
Finalizes the MariaDB Connector/C library after use, performing memory cleanup and shutting down the embedded server if applicable.
Initializes the MariaDB Connector/C library before any other functions are called, starting the embedded server if used in that configuration.
Indicates whether additional result sets remain from a previous multi-statement query, returning 1 if more results are available.
Returns the length of a length-encoded field and advances the pointer past it.
Reads the next protocol packet from the server into the connection's network buffer.
Advances to the next result set from a multi-statement query, making it available for retrieval via mysql_store_result or mysql_use_result.
Retrieves the column count from a result set handle, useful for iterating over fields in a MariaDB query result.
Returns the number of rows in a MariaDB result set; for unbuffered results the count is only accurate after all rows have been fetched.
Sets extra connection options that take two arguments; call after mysql_init() and before mysql_real_connect().
Sets extra connection options on a MYSQL handle before calling mysql_real_connect. Deprecated since Connector/C 3.0 — use mysql_optionsv instead.
Sets connection, TLS, plugin, and option-file options on a MariaDB Connector/C handle before mysql_real_connect, supporting a variable argument list.
Checks whether a MariaDB server connection is still active and attempts an automatic reconnect if the connection has dropped and reconnect is enabled.
Sends a null-terminated SQL string to the MariaDB server for execution, returning zero on success; use mysql_real_query for binary-safe operation.
Reads the result of a statement previously sent with mysql_send_query, and must be called once for each successful mysql_send_query call.
Opens a connection to a MariaDB server and returns a MYSQL handle on success, or NULL if the connection could not be established.
Encodes a string for safe use in a SQL statement, taking the connection's current character set into account when escaping special characters.
Sends a binary-safe SQL statement to a MariaDB server; use mysql_num_fields to determine whether the query returned a result set.
Flushes server-side caches and state using a bitmask of options such as REFRESH_GRANT, REFRESH_LOG, REFRESH_TABLES, and REFRESH_HOSTS.
Resets session state on a MariaDB Connector/C connection — rolling back transactions and clearing variables — without disconnecting or reauthenticating.
Undoes the current transaction for a database connection; it has no effect if autocommit is enabled or the engine is non-transactional.
Repositions the row cursor in a buffered MariaDB result set to an arbitrary offset, returning the previous row position as a MYSQL_ROW_OFFSET.
Returns the current row cursor offset for a buffered MariaDB result set, which can then be passed to mysql_row_seek to restore that position.
Changes the default database on an active connection; the current default can also be queried with the SELECT DATABASE() SQL function.
Dispatches a query asynchronously on a MariaDB connection; each call must be followed by mysql_read_query_result to consume the response.
Is an alias for mysql_library_end in MariaDB Connector/C, used to finalize and clean up the client library.
Is an alias for mysql_library_init in MariaDB Connector/C, used to initialize the client library before making any other calls.
Retrieves the first session state change notification from the server, covering schema changes, system variables, and state flags. Added in Connector/C 3.0.
Retrieves subsequent session state change notifications after mysql_session_track_get_first, called repeatedly until a nonzero value signals end of data.
Sets the default character set for a MariaDB Connector/C connection, ensuring mysql_real_escape_string uses the correct encoding.
Enables or disables multi-statement support on a MariaDB connection using MYSQL_OPTION_MULTI_STATEMENTS_ON or _OFF.
Registers custom callback functions for init, read, end, and error phases of a LOAD DATA LOCAL INFILE operation in MariaDB Connector/C.
Resets local infile callbacks to the Connector/C internal defaults, reversing any custom handler registered via mysql_set_local_infile_handler.
Sends a shutdown request to the MariaDB server over the current connection, requiring the SHUTDOWN privilege for the authenticated user.
Returns the five-character SQLSTATE error code for the most recent MariaDB Connector/C function call, with 00000 indicating success.
Configures TLS parameters including key, certificate, CA, and cipher list for a MariaDB connection, and must be called before mysql_real_connect.
Returns a status string from the MariaDB server covering uptime, active threads, query count, open tables, and queries per second.
Retrieves a complete buffered result set from the last executed MariaDB query, returning NULL on error or for non-SELECT statements.
Releases thread-local memory allocated by mysql_thread_init and must be called explicitly before a thread exits to avoid memory leaks. Deprecated in Connector/C 3.0.
Retrieves the thread identifier for an active connection; the value may change after a reconnect if the reconnect option is enabled.
Initializes thread-local variables for multi-threaded Connector/C clients; called automatically by mysql_init if not invoked explicitly. Deprecated in Connector/C 3.0.
Returns 1 if the MariaDB Connector/C client library was compiled with thread-safety support, or zero otherwise.
Initiates unbuffered retrieval of a query result set row by row from the MariaDB server, blocking the connection until all rows are fetched or freed.
Retrieves the warning count from the most recent query execution; use SHOW WARNINGS for the full warning message text.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

