table of contents
mysql_optionsv(3) | MariaDB Connector/C | mysql_optionsv(3) |
Name¶
mysql_optionsv - Used to set extra connect options and affect behavior of a connection
Synopsis¶
-
#include <mysql.h> int mysql_optionsv(MYSQL * mysql,
enum mysql_option,
const void * arg,
...);
Description¶
Used to set extra connect options and affect behavior for a connection. This function may be called multiple times to set several options. mysql_optionsv() should be called after mysql_init(3).
Options¶
The following table shows which variable type to use for each option.
Variable Type | Values |
my_bool | MYSQL_OPT_RECONNECT, MYSQL_OPT_LOCAL_INFILE, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_SSL_ENFORCE, MYSQL_OPT_SSL_VERIFY_SERVER_CERT |
unsigned int | MYSQL_OPT_PORT, MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT |
unsigned long | MYSQL_OPT_NET_BUFFER_LENGTH, MYSQL_OPT_MAX_ALLOWED_PACKET |
const 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 |
- | MYSQL_OPT_CONNECT_ATTR_RESET |
- •
- MYSQL_INIT_COMMAND
Command(s) which will be 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 compressed protocol, the default protocol will be used.
- •
- MYSQL_OPT_CONNECT_TIMEOUT
Connect timeout in seconds. This value will be passed as an unsigned ##int## parameter.
- •
- MYSQL_OPT_LOCAL_INFILE
Enable or disable the use of LOAD DATA LOCAL INFILE
- •
- MYSQL_OPT_NAMED_PIPE
For Windows operating systems only: Use named pipes for client/server communication.
- •
- MYSQL_PROGRESS_CALLBACK
Specifies a callback function which will be able to visualize the progress of certain long running statements (i.e. LOAD DATA LOCAL INFILE or ALTER 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_PIPE and MYSQL_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 named configuration file. To read from default my.cnf configuration file, a NULL pointer has to be passed with option MYSQL_READ_DEFAULT_GROUP. Note: MariaDB Connector/C will not read the configuration by default. If MYSQL_READ_DEFAULT_FILE is specified the following sections will be always processed:
- •
- [client]
- •
- [client-server]
- •
- [client-mariadb]
- •
- MYSQL_READ_DEFAULT_GROUP
Read options from the named group from [[configuring-mariadb-with-mycnf|my.cnf]] or the file specified with MYSQL_READ_DEFAULT_FILE.
- •
- 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 for MYSQL_OPT_NONBLOCK is 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.
- •
- 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 *)"ssh_user", (void *)ssh_user);
- •
- 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 the CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS capability flag. If the password has expired and CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS is set, the server will not return an error when connecting, but put the connection in sandbox mode, where all commands will return error 1820 (ER_MUST_CHANGE_PASSWORD) unless a new password was set. This option was added in MariaDB Connector/C 3.0.4
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 with MARIADB_OPT_PASSPHRASE option.
- •
- 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
Specify one or more (SSLv3, TLSv1.0 or TLSv1.2) cipher suites for TLS encryption. Even if Connector/C supports TLSv1.3 protocol, it is not possible yet to specify TLSv1.3 cipher suites.
- •
- MYSQL_OPT_SSL_CRL
Specify a file with a certificate revocation list.
- •
- MYSQL_OPT_SSL_CRLPATH
Specify a directory with contains files with certificate revocation lists.
- •
- MARIADB_OPT_SSL_FP
Specify the SHA1 fingerprint of a server certificate for validation during the TLS handshake.
- •
- MARIADB_OPT_SSL_FP
Specify a file which contains one or more SHA1 fingerprints of server certificates for validation during the TLS handshake.
- •
- MARIADB_OPT_SSL_PASPHRASE
Specify a passphrase for a passphrase protected client key.
- •
- MYSQL_OPT_SSL_VERIFY_SERVER_CERT
Enable (or disable) the verification of the hostname against common name (CN) of the server’s host certificate.
- •
- 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 option is used by the caching_sha2_password plugin and was added in Connector/C 3.1.0
- •
- MARIADB_OPT_TLS_CIPHER_STRENGTH
This option is not in use anymore.
Connection Attributes¶
Connection attributes are stored in the session_connect_attrs and session_account_connect_attrsPerformance 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. x86 or x64 * _server_host: the hostname (as specified in mysql_real_connect). This attribute was added in Connector/C 3.0.5
Note: If the Performance Schema is disabled, connection attributes will not be stored on server.
- •
- MYSQL_OPT_CONNECT_ATTR_DELETE
Deletes a connection attribute for the given key.
- •
- MYSQL_OPT_CONNECT_ATTR_ADD
Adds a key/value pair to connection attributes.
- •
- MYSQL_OPT_CONNECT_ATTR_RESET
Clears the current list of connection attributes.
See Also¶
Version 3.2.2 |