mysql_optionsv(3)
π NAME π
Okay bestie, gather round β this is the man page for mysql_optionsv from MariaDB Connector/C (that's the (3) section, library calls, iykyk). β¨
mysql_optionsv is the girl whose whole job is setting extra connect options and controlling how a connection behaves. She's not the main character of your app, but she runs the backstage. π
β¨ SYNOPSIS β¨
#include <mysql.h>
int mysql_optionsv(MYSQL * mysql,
enum mysql_option,
const void * arg,
...);
π DESCRIPTION π
So here's the vibe: mysql_optionsv sets extra connect options and affects the behavior of a connection. π¦
You can call it multiple times to set several different options β she does not mind, she's flexible like that. π
β οΈ Important: callmysql_optionsv()aftermysql_init(3). Order matters, bestie, don't skip steps. π
πΈ OPTIONS πΈ
Here's the tea on which variable type goes with which option</puru> π« (the original lays this out as a table, but tables are not the vibe here, so):
my_boolβMYSQL_OPT_RECONNECT,MYSQL_SECURE_AUTH,MYSQL_REPORT_DATA_TRUNCATION,MYSQL_OPT_SSL_ENFORCE,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,MARIADB_OPT_SKIP_READ_RESPONSEunsigned intβMYSQL_OPT_PORT,MYSQL_OPT_LOCAL_INFILE,MYSQL_OPT_CONNECT_TIMEOUT,MYSQL_OPT_PROTOCOL,MYSQL_OPT_READ_TIMEOUT,MYSQL_OPT_WRITE_TIMEOUTunsigned longβMYSQL_OPT_NET_BUFFER_LENGTH,MYSQL_OPT_MAX_ALLOWED_PACKETconst char *βMYSQL_INIT_COMMAND,MARIADB_OPT_UNIXSOCKET,MARIADB_OPT_PASSWORD,MARIADB_OPT_USER,MARIADB_OPT_HOST,MARIADB_OPT_SCHEMA,MYSQL_OPT_SSL_KEY,MYSQL_OPT_SSL_CERT,MYSQL_OPT_SSL_CA,MYSQL_OPT_SSL_CAPATH,MYSQL_SET_CHARSET_NAME,MYSQL_SET_CHARSET_DIR,MYSQL_OPT_SSL_CIPHER,MYSQL_SHARED_MEMORY_BASE_NAME,MYSQL_PLUGIN_DIR,MYSQL_DEFAULT_AUTH,MARIADB_OPT_SSL_FP,MARIADB_OPT_SSL_FP_LIST,MARIADB_OPT_TLS_PASSPHRASE,MARIADB_OPT_TLS_VERSION,MYSQL_OPT_BIND,MYSQL_OPT_CONNECT_ATTR_DELETE,MYSQL_OPT_CONNECT_ATTR_ADD,MARIADB_OPT_CONNECTION_HANDLER,MYSQL_SERVER_PUBLIC_KEY,MARIADB_OPT_RESTRICTED_AUTHconst char*,unsigned intβMARIADB_OPT_RPL_REGISTER_REPLICA-βMYSQL_OPT_CONNECT_ATTR_RESETvoid *βMARIADB_OPT_PROXY_HEADER
Now the options themselves, one by one, no skipping, we are thorough in this house π :
MYSQL_OPT_SSL_ENFORCEβ Turn TLS on or off. You can use this to enable TLS without having to hand over TLS certificates, keys or CAs. π
β οΈ Heads up fr: currently this does not actually enforce TLS, even though the name would 100% make you think it does. If the server doesn't support TLS, the protocol falls back to unencrypted communication. π If you actually want to enforce TLS, use MYSQL_OPT_SSL_VERIFY_SERVER_CERT instead.
MYSQL_INIT_COMMANDβ Command(s) that get executed when connecting and reconnecting to the server. πMYSQL_OPT_COMPRESSβ Use the compressed protocol for client/server communication. If the server doesn't support the compressed protocol, the default protocol will be used. ποΈMYSQL_OPT_CONNECT_TIMEOUTβ Connect timeout in seconds. This value gets passed as anunsigned intparameter. β±οΈMYSQL_OPT_LOCAL_INFILEβ Enable or disable the use ofLOAD DATA LOCAL INFILE.MYSQL_OPT_NAMED_PIPEβ Windows only, bestie πͺ: use named pipes for client/server communication.MYSQL_PROGRESS_CALLBACKβ Specifies a callback function that will be able to visualize the progress of certain long running statements (i.e.LOAD DATA LOCAL INFILEorALTER TABLE). π The callback function must be defined as followed:
static void report_progress(const MYSQL *mysql __attribute__((unused)),
uint stage, uint max_stage,
double progress __attribute__((unused)),
const char *proc_info __attribute__((unused)),
uint proc_info_length __attribute__((unused)))
MYSQL_OPT_PROTOCOLβ Specify the type of client/server protocol. Possible values are:MYSQL_PROTOCOL_TCP,MYSQL_PROTOCOL_SOCKET,MYSQL_PROTOCOL_PIPEandMYSQL_PROTOCOL_MEMORY.MYSQL_OPT_RECONNECTβ Enable or disable automatic reconnect. πMYSQL_OPT_READ_TIMEOUTβ Specifies the timeout in seconds for reading packets from the server.MYSQL_OPT_WRITE_TIMEOUTβ Specifies the timeout in seconds for sending packets to the server.MYSQL_READ_DEFAULT_FILEβ Read options from the specified configuration file. If an empty string is passed, the default configuration files (such as/etc/my.cnf,/etc/mysql/my.cnf) will be read. By default, configuration files are not processed unless this option is specified. πMYSQL_READ_DEFAULT_GROUPβ Read options from the specified group within the default configuration file or the file specified byMYSQL_READ_DEFAULT_FILE. Passing an empty string will result in all sections being processed. If no specific file is provided viaMYSQL_READ_DEFAULT_FILE, all available default configuration files will be considered.
π Note: In addition to a specified group, the following groups will always be processed: -[client]-[client-server]-[client-mariadb]
MYSQL_REPORT_DATA_TRUNCATIONβ Enable or disable reporting data truncation errors for prepared statements.MYSQL_OPT_BINDβ Specify the network interface from which to connect to MariaDB Server. πMYSQL_PLUGIN_DIRβ Specify the location of client plugins.MYSQL_OPT_NONBLOCKβ Specify stack size for non blocking operations. The argument forMYSQL_OPT_NONBLOCKis the size of the stack used to save the state of a non-blocking operation while it is waiting for I/O and the application is doing other processing. Normally, applications will not have to change this, and it can be passed as zero to use the default value. π§MYSQL_OPT_NET_BUFFER_LENGTHβ Initial network buffer size in bytes. The default value is16777216(16MiB).MYSQL_OPT_MAX_ALLOWED_PACKETβ Maximum allowed packet length. The default value is1073741824(1GiB) on the client side. If the limit is exceeded by a packet sent by the server, an error is generated. π€MARIADB_OPT_CONNECTION_HANDLERβ Specify the name of a connection handler plugin. πMARIADB_OPT_USERDATAβ Bundle user data to the current connection, e.g. for use in connection handler plugins. This option requires 4 parameters: connection, option, key and value:
mysql_optionsv(mysql, MARIADB_OPT_USERDATA, (void *)"my_key", (void *)value);
MARIADB_OPT_CONNECTION_READ_ONLYβ This option is used by connection handler plugins and indicates that the current connection will be used for read operations only. πMYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDSβ If this option is set, the client indicates that it will be able to handle expired passwords by setting theCLIENT_CAN_HANDLE_EXPIRED_PASSWORDScapability flag. If the password has expired andCLIENT_CAN_HANDLE_EXPIRED_PASSWORDSis set, the server will not return an error when connecting, but put the connection in sandbox mode, where all commands will return error1820(ER_MUST_CHANGE_PASSWORD) unless a new password was set. π This option was added in MariaDB Connector/C3.0.4.MARIADB_OPT_STATUS_CALLBACKβ Specifies a callback function which will be called whenever the server status changes or the server sentsession_trackinformation to the client:
mysql_optionsv(mysql, MARIADB_OPT_STATUS_CALLBACK, function, data)
The callback function must be defined as follows:
void status_callback(void *data, enum enum_mariadb_status_info type, ..)
Parameters:
dataβ Pointer passed with registration of callback function (usually a connection handle)typeβ Information typeSTATUS_TYPEorSESSION_TRACK_TYPE
Variadic Parameters:
- if
(type == STATUS_TYPE):- server status (
unsigned int)
- server status (
- if
(type == SESSION_TRACK_TYPE)enum enum_session_state_type track_typeβ session track type- if
(track_type == SESSION_TRACK_SYSTEM_VARIABLES)MARIADB_CONST_STRING *keyMARIADB_CONST_STRING *value
- else
MARIADB_CONST_STRING *value
β οΈ Note: Specifying a callback function overwrites the internal session tracking function, so API functionsmysql_session_track_get_first()/next()can't be used. π
An example can be found in unittest/libmariadb/connection.c (test_status_callback) π
Added in version 3.3.2.
MARIADB_OPT_SKIP_READ_RESPONSEβ Don't read response packets in binary protocol.
Added in version 3.1.13.
π Replication/Binlog API options π
MARIADB_OPT_RPL_REGISTER_REPLICAβ Specifies host name and port for Binlog/API. When this option was set,rpl_open()will register replica withserver_id, host and port to the connected server. This information can be retrieved bySHOW SLAVE STATUScommand. π This option was added in version3.3.1.
π TLS/SSL and Security options π
MYSQL_OPT_SSL_KEYβ Specify the name of a key for a secure connection. If the key is protected with a passphrase, the passphrase needs to be specified withMARIADB_OPT_PASSPHRASEoption. ποΈMYSQL_OPT_SSL_CERTβ Specify the name of a certificate for a secure connection. πMYSQL_OPT_SSL_CAβ Specify the name of a file which contains one or more trusted CAs. ποΈMYSQL_OPT_SSL_CAPATHβ Specify the path which contains trusted CAs. πMYSQL_OPT_SSL_CIPHERβ bestie, this is where you list one or more cipher suites (fromSSLv3,TLSv1.0orTLSv1.2) for TLS encryption. And yes, even though Connector/C does support theTLSv1.3protocol, you literally cannot specifyTLSv1.3cipher suites yet. That's just the situation. π«MYSQL_OPT_SSL_CRLβ points at a file that holds a certificate revocation list. πMYSQL_OPT_SSL_CRLPATHβ points at a directory, and that directory contains files with certificate revocation lists. It's giving "one file, but make it a whole folder". πMARIADB_OPT_SSL_FPβ here's where you drop the fingerprint hash of a server certificate so it can get validated during the TLS handshake. Version tea: for versions before3.4.0the hash is a SHA1 hash, and for3.4.0and newer it's SHA256, SHA384 or SHA512. glow-up fr fr β¨MARIADB_OPT_SSL_FP_LISTβ same vibe as above but it's a file, and that file contains one or more fingerprint hashes of server certificates for validation during the TLS handshake. And same version lore: before3.4.0it's a SHA1 hash,3.4.0and newer it's SHA256, SHA384 or SHA512. πMARIADB_OPT_SSL_PASPHRASEβ yes that's how it's spelled, don't come for me π β this specifies a passphrase for a passphrase protected client key.MYSQL_OPT_SSL_VERIFY_SERVER_CERTβ turn on (or off) the verification of the host name against the common name (CN) of the server's host certificate. Main character security energy, no cap. πMYSQL_SERVER_PUBLIC_KEYβ specifies the name of the file which contains the RSA public key of the database server. The format of this file must be in PEM format. This one is used by thecaching_sha2_passwordplugin and was added in Connector/C3.1.0. πΈMARIADB_OPT_TLS_CIPHER_STRENGTHβ this option is not in use anymore. she's retired, we love her, we don't use her πMARIADB_OPT_RESTRICTED_AUTHβ specifies one or more comma separated authentication plugins which are allowed for authentication. If the database server asks for an authentication plugin that is not listed in this option, MariaDB Connector/C will return an error. This option was added in MariaDB Connector/C3.3.0. π
π¦ Proxy settings π¦
Okay so per the proxy protocol specification, the connecting client can prefix its first packet with a proxy protocol header. The server will parse that header and assume the client's IP address is the one set in the proxy header. Sneaky but legal, iykyk.
MARIADB_OPT_PROXY_HEADERβ specifies the proxy header which will be prefixed to the first packet. The parameters arevoid *for the prefix buffer andsize_tfor the length of the buffer:
const char *hdr="PROXY TCP4 192.168.0.1 192.168.0.11 56324 443\r\n";
mysql_optionsv(mysql, MARIADB_OPT_PROXY_HEADER, hdr, strlen(hdr));
π Connection Attributes π
Connection attributes are stored in the session_connect_attrs and session_account_connect_attrs Performance Schema tables. By default, MariaDB Connector/C sends the following connection attributes to the server:
_client_name: always"libmariadb"_client_version: version of MariaDB Connector/C_os: operation system_pid: process id_platform: e.g.x86orx64_server_host: the host name (as specified inmysql_real_connect). This attribute was added in Connector/C3.0.5
Note: if the Performance Schema is disabled, connection attributes will not be stored on server. So like, they just vanish. π«Ά
MYSQL_OPT_CONNECT_ATTR_DELETEβ deletes a connection attribute for the given key. bye bestie πMYSQL_OPT_CONNECT_ATTR_ADDβ adds a key/value pair to connection attributes. And heads up: the total length of the stored connection attributes is limited to a maximum of65535bytes. That's the ceiling, fr fr.MYSQL_OPT_CONNECT_ATTR_RESETβ clears the current list of connection attributes. fresh start energy β¨
π See Also π
mysql_init(3) mysql_real_connect(3)
and that's the whole page, babe β Version 3.4 of mysql_optionsv(3), served fresh. go forth and configure responsibly π
π¦ where this page comes from
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms