All pages
Powered by GitBook
1 of 1

Loading...

mysql_optionsv

Syntax

  • mysql - a mysql handle, which was previously allocated by mysql_init() or mysql_real_connect().

  • mysql_option - the option to set. See description below.

  • arg - the value for the option.

  • ... - variable argument list.

Description

Used to set extra connect options and affect behavior for a connection. This function may be called multiple times to set several options. All calls pass numeric literal values for a const void *. mysql_optionsv() should be called after .

Some of these options can also be set in , such as my.cnf.

Returns

Returns zero on success, non-zero if an error occurred (invalid option or value).

Options

  • MYSQL_INIT_COMMAND: lets you specify a command to execute immediately after connecting (and also after a reconnect if enabled).

    • Each call adds one SQL statement to an internal list; all stored commands are executed in order.

    • You cannot concatenate multiple statements with semicolons; each statement must be added with a separate call.

Connection Options

Some of these options can also be set as arguments to the function.

  • MARIADB_OPT_HOST: Hostname or IP address of the server to connect to.

  • MARIADB_OPT_USER: User to login to the server.

  • MARIADB_OPT_PASSWORD: Password of the user to login to the server.

TLS Options

  • MYSQL_OPT_SSL_KEY: Defines a path to a private key file to use for . This option requires that you use the absolute path, not a relative path. If the key is protected with a passphrase, the passphrase needs to be specified with MARIADB_OPT_TLS_PASSPHRASE option.

  • MYSQL_OPT_SSL_CERT: Defines a path to the X509 certificate file to use for . This option requires that you use the absolute path, not a relative path.

  • MYSQL_OPT_SSL_CA

Plugin Options

  • MYSQL_DEFAULT_AUTH: Default authentication client-side plugin to use.

  • MYSQL_ENABLE_CLEARTEXT_PLUGIN: This option is supported to be compatible with MySQL client libraries. MySQL client libraries use this option to determine whether the authentication plugin can be used. However, MariaDB clients and client libraries do not need to set any options in order to use this authentication plugin. Therefore, this option does not actually do anything in MariaDB Connector/C.

  • MARIADB_OPT_CONNECTION_HANDLER: Specify the name of a connection handler plugin.

Option File Options

  • MYSQL_READ_DEFAULT_FILE: Read options from an .

  • MYSQL_READ_DEFAULT_GROUP: Read options from the named from an .

These options work together, according to the following rules:

  • if both are set to NULL, then no option files are read.

  • if MYSQL_READ_DEFAULT_FILE is set to an empty string (or NULL and MYSQL_READ_DEFAULT_GROUP is set) then all are read.

  • if MYSQL_READ_DEFAULT_FILE

Connection Attribute Options

Connection attributes are stored in the and 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

If the 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

int mysql_optionsv(MYSQL * mysql,
                   enum mysql_option,
                   const void * arg,
                   ...);
MYSQL_OPT_CONNECT_TIMEOUT: Connect timeout in seconds. This value will be passed as an unsigned int parameter.
  • MARIADB_OPT_VERIFY_LOCAL_INFILE_CALLBACK: Specifies a callback function for filename and/or directory verification. This option was added in Connector/C 2.3.0

  • 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 ).

  • 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_REPORT_DATA_TRUNCATION: Enable or disable reporting data truncation errors for prepared statements.

  • MYSQL_SET_CHARSET_DIR: files.

  • MYSQL_SET_CHARSET_NAME: Specify the default for the connection.

  • MYSQL_OPT_BIND: Specify the network interface from which to connect to MariaDB Server.

  • 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.

  • 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

  • MYSQL_OPT_MAX_ALLOWED_PACKET: The maximum packet length to send to or receive from server. The default is 16MB, the maximum 1GB.

  • MYSQL_OPT_NET_BUFFER_LENGTH: The buffer size for TCP/IP and socket communication. Default is 16KB.

  • MARIADB_OPT_SCHEMA: Database to use.
  • MARIADB_OPT_PORT: Port number to use for connection.

  • MARIADB_OPT_UNIXSOCKET: For connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • MYSQL_OPT_NAMED_PIPE: For Windows operating systems only: Use named pipes for client/server communication.

  • MYSQL_OPT_PROTOCOL: Specify the type of client/server protocol. Possible values are:

    • MYSQL_PROTOCOL_TCP

    • MYSQL_PROTOCOL_SOCKET

    • MYSQL_PROTOCOL_PIPE

    • MYSQL_PROTOCOL_MEMORY.

  • MARIADB_OPT_FOUND_ROWS: Return the number of matched rows instead of number of changed rows.

  • 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_LOCAL_INFILE: Enable or disable the use of LOAD DATA LOCAL INFILE

  • MARIADB_OPT_MULTI_STATEMENTS: Allows the client to send multiple statements in one command. Statements will be divided by a semicolon.

  • MARIADB_OPT_MULTI_RESULTS: Indicates that the client is able to handle multiple result sets from stored procedures or multi statements. This option will be automatically set if MARIADB_OPT_MULTI_STATEMENTS is set.

  • MYSQL_SHARED_MEMORY_BASE_NAME: Shared-memory name to use for Windows connections using shared memory to a local server (started with the --shared-memory option). Case-sensitive.

  • : Defines a path to a PEM file that should contain one or more X509 certificates for trusted Certificate Authorities (CAs) to use for
    . This option requires that you use the absolute path, not a relative path. See
    for more information.
  • MYSQL_OPT_SSL_CAPATH: Defines a path to a directory that contains one or more PEM files that should each contain one X509 certificate for a trusted Certificate Authority (CA) to use for . This option requires that you use the absolute path, not a relative path. The directory specified by this option needs to be run through the openssl rehash command. See for more information. This option is only supported if the connector was built with OpenSSL. If the connector was built with GnuTLS or Schannel, then this option is not supported. See for more information about which libraries are used on which platforms.

  • MYSQL_OPT_SSL_CIPHER: Defines a list of permitted ciphers or cipher suites to use for .

  • MYSQL_OPT_SSL_CRL: Defines a path to a PEM file that should contain one or more revoked X509 certificates to use for . This option requires that you use the absolute path, not a relative path. See for more information. This option is only supported if the connector was built with OpenSSL or Schannel. If the connector was built with GnuTLS, then this option is not supported. See for more information about which libraries are used on which platforms.

  • MYSQL_OPT_SSL_CRLPATH: Defines a path to a directory that contains one or more PEM files that should each contain one revoked X509 certificate to use for . This option requires that you use the absolute path, not a relative path. The directory specified by this option needs to be run through the openssl rehash command. See for more information. This option is only supported if the connector was built with OpenSSL. If the connector was built with GnuTLS or Schannel, then this option is not supported. See for more information about which libraries are used on which platforms.

  • MARIADB_OPT_SSL_FP: Specify the SHA1 fingerprint of a server certificate for validation during the handshake. This is deprecated. Use MARIADB_OPT_TLS_PEER_FP instead.

  • MARIADB_OPT_TLS_PEER_FP: Specify the SHA1 fingerprint of a server certificate for validation during the handshake.

  • MARIADB_OPT_SSL_FP_LIST: Specify a file which contains one or more SHA1 fingerprints of server certificates for validation during the handshake. This is deprecated. Use MARIADB_OPT_TLS_PEER_FP_LIST instead.

  • MARIADB_OPT_TLS_PEER_FP_LIST: Specify a file which contains one or more SHA1 fingerprints of server certificates for validation during the handshake.

  • MARIADB_OPT_TLS_PASSPHRASE: Specify a passphrase for a passphrase-protected private key, as configured by the MYSQL_OPT_SSL_KEY option. This option is only supported if the connector was built with OpenSSL or GnuTLS. If the connector was built with Schannel, then this option is not supported. See for more information about which libraries are used on which platforms.

  • MARIADB_OPT_TLS_VERSION: Defines which protocol versions are allowed. This should be a comma-separated list of TLS protocol versions to allow. Valid TLS protocol versions are TLSv1.0, TLSv1.1, TLSv1.2, and TLSv1.3. Both the client and server should support the allowed TLS protocol versions. See for information on which TLS libraries support which TLS protocol versions. See for more information about which TLS libraries are used on which platforms.

  • MYSQL_OPT_SSL_VERIFY_SERVER_CERT: Enables (or disables) .

  • MYSQL_OPT_SSL_ENFORCE: Whether to force . This enables TLS with the default system settings. It does not prevent the connection from being created if the server does not support TLS.

  • MARIADB_OPT_TLS_CIPHER_STRENGTH: Cipher strength. This value will be passed as an unsigned int parameter.

  • 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.

  • 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_PLUGIN_DIR: Specify the location of client plugins. The plugin directory can also be specified with the MARIADB_PLUGIN_DIR environment variable.

  • MYSQL_SECURE_AUTH: Refuse to connect to the server if the server uses the authentication plugin. This mode is off by default, which is a difference in behavior compared to MySQL 5.6 and later, where it is on by default.

  • 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 client authentication plugin. It was introduced in Connector/C 3.1.0.

  • is set to a non-empty string, then it is interpreted as a path to a
    , and only that option file is read.
  • if MYSQL_READ_DEFAULT_GROUP is an empty string (or NULL and MYSQL_READ_DEFAULT_FILE is set) then only default groups — [client], [client-server], [client-mariadb] are read.

  • if MYSQL_READ_DEFAULT_GROUP is a non-empty string, then it is interpreted as a custom option group, and that custom option group is read in addition to default groups from above.

  • _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

  • mysql_init()
    option files
    mysql_real_connect
    option file
    option group
    option file
    default option files
    mysql_init()
    mysql_options()
    mysql_real_connect()
    custom option file
    int my_verify_filename(void *data, const char *filename)
    {
     return strcmp((char *)data, filename);
    }
    ...
    char *filename= "mydata.csv";
    mysql_optionsv(mysql, MARIADB_OPT_VERIFY_LOCAL_INFILE_CALLBACK, my_verify_filename, (void *)filename);
    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_optionsv(mysql, MYSQL_PROGRESS_CALLBACK, (void *)report_progress);
    my_bool reconnect= 1; /* enable reconnect */
    mysql_optionsv(mysql, MYSQL_OPT_RECONNECT, (void *)&reconnect);
    unsigned int timeout= 5;
    mysql_optionsv(mysql, MYSQL_OPT_READ_TIMEOUT, (void *)&timeout);
    unsigned int timeout= 5;
    mysql_optionsv(mysql, MYSQL_OPT_WRITE_TIMEOUT, (void *)&timeout);
    mysql_optionsv(mysql, MYSQL_REPORT_DATA_TRUNCATION, NULL); /* disable */
    mysql_optionsv(mysql, MYSQL_REPORT_DATA_TRUNCATION, (void *)"1"); /* enable */
    mysql_optionsv(mysql, MYSQL_SET_CHARSET_DIR, (void *)"/usr/local/mysql/share/mysql/charsets");
    mysql_optionsv(mysql, MYSQL_SET_CHARSET_NAME, (void *)"utf8");
    mysql_optionsv(mysql, MYSQL_OPT_BIND, (void *)"192.168.8.3");
    mysql_optionsv(mysql, MYSQL_OPT_NONBLOCK, 0);
    mysql_optionsv(mysql, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1);
    mysql_optionsv(mysql, MYSQL_OPT_MAX_ALLOWED_PACKET, 0x40000000);
    mysql_optionsv(mysql, MYSQL_OPT_NET_BUFFER_LENGTH, 0x40000000);
    mysql_optionsv(mysql, MARIADB_OPT_PORT, 3307);
    mysql_optionsv(mysql, MARIADB_OPT_UNIXSOCKET, (void *)"/var/lib/mysql/mysql.sock");
    mysql_optionsv(mysql, MYSQL_OPT_NAMED_PIPE, NULL);
    mysql_optionsv(mysql, MARIADB_OPT_FOUND_ROWS, 1);
    mysql_optionsv(mysql, MYSQL_OPT_COMPRESS, NULL);
    unsigned int enable= 1, disable= 0;
    mysql_optionsv(mysql, MYSQL_OPT_LOCAL_INFILE, (void *)&disable);/* disable */
    mysql_optionsv(mysql, MYSQL_OPT_LOCAL_INFILE, (void *)NULL);     /* enable */
    mysql_optionsv(mysql, MYSQL_OPT_LOCAL_INFILE, (void *)&enable); /* enable */
    mysql_optionsv(mysql, MARIADB_OPT_MULTI_STATEMENTS, (void *)"");
    mysql_optionsv(mysql, MARIADB_OPT_MULTI_RESULTS, 1);
    mysql_optionsv(mysql, MYSQL_SHARED_MEMORY_BASE_NAME, (void *)"mariadb");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_CAPATH, (void *)"certs/ca-cert.pem");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_CIPHER, (void *)"DHE-RSA-AES256-SHA");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_CAPATH, (void *)"certs/ca-cert.pem");\\\\<<code>>mysql_optionsv(mysql, MYSQL_OPT_SSL_CRL, (void *)"certs/crl.pem");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_CAPATH, (void *)"certs/ca-cert.pem");\\\\<<code>>mysql_optionsv(mysql, MYSQL_OPT_SSL_CRLPATH, (void *)"certs/crls");
    mysql_optionsv(mysql, MARIADB_OPT_SSL_FP, (void *)"3a079e1a14ad326953a5d280f996b93d772a5bea");
    mysql_optionsv(mysql, MARIADB_OPT_TLS_PEER_FP, (void *)"3a079e1a14ad326953a5d280f996b93d772a5bea");
    mysql_optionsv(mysql, MARIADB_OPT_SSL_FP_LIST, (void *)"certs/fingerprints.txt");
    mysql_optionsv(mysql, MARIADB_OPT_TLS_PEER_FP_LIST, (void *)"certs/fingerprints.txt");
    mysql_optionsv(mysql, MARIADB_OPT_SSL_PASSPHRASE, (void *)"thisisashortpassphrase");
    mysql_optionsv(mysql, MARIADB_OPT_TLS_VERSION, (void *)"TLSv1.2,TLSv1.3");
    my_bool verify= 1;
    mysql_optionsv(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (void *)&verify);
    my_bool enforce_tls= 1;
    mysql_optionsv(mysql, MYSQL_OPT_SSL_ENFORCE, (void *)&enforce_tls);
    unsigned int cipher_strength= 128;
    mysql_optionsv(mysql, MARIADB_OPT_TLS_CIPHER_STRENGTH, (void*)&cipher_strength);
    mysql_optionsv(mysql, MARIADB_OPT_USERDATA, (void *)"ssh_user", (void *)ssh_user);
    my_bool read_only= 1;
    mysql_optionsv(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, (void *)&read_only);
    mysql_optionsv(mysql, MYSQL_PLUGIN_DIR, (void *)"/opt/mariadb/lib/plugins");
    mysql_optionsv(mysql, MYSQL_SECURE_AUTH, 1);
    mysql_optionsv(mysql, MYSQL_SERVER_PUBLIC_KEY, (void *)(void *)"certs/server-cert.pem);
    mysql_optionsv(mysql, MYSQL_INIT_COMMAND, (void *)"CREATE TABLE test.t1(a int)");
    mysql_optionsv(mysql, MYSQL_INIT_COMMAND, (void *)"SET @value := 1");
    mysql_optionsv(mysql, MARIADB_OPT_HOST, (void *)"dbserver.example.com");
    mysql_optionsv(mysql, MARIADB_OPT_USER, (void *)"myuser");
    mysql_optionsv(mysql, MARIADB_OPT_PASSWORD, (void *)"horsebattery");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_KEY, (void *)"certs/client-key.pem");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_CERT, (void *)"certs/client-cert.pem");
    mysql_optionsv(mysql, MYSQL_DEFAULT_AUTH, (void *)"ed25519");
    mysql_optionsv(mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, 1);
    mysql_optionsv(mysql, MARIADB_OPT_CONNECTION_HANDLER, (void *)"aurora");
    mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, (void *)"app_version");
    mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, (void *)"app_version", (void *)"2.0.1");
    mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
    unsigned int timeout= 5;
    mysql_optionsv(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&timeout);
    mysql_optionsv(mysql, MARIADB_OPT_SCHEMA, (void *)"mydb");
    mysql_optionsv(mysql, MYSQL_OPT_SSL_CA, (void *)"certs/ca-cert.pem");
    enum mysql_protocol_type prot_type= MYSQL_PROTOCOL_SOCKET;
    mysql_optionsv(mysql, MYSQL_OPT_PROTOCOL, (void *)&prot_type);
    TLS
    TLS
    mysql_clear_password
    session_connect_attrs
    session_account_connect_attrs
    Performance Schema
    ALTER TABLE
    character set
    character set
    TLS
    Secure Connections Overview: Certificate Authorities (CAs)
    TLS
    Secure Connections Overview: Certificate Authorities (CAs)
    TLS and Cryptography Libraries Used by MariaDB
    TLS
    TLS
    Secure Connections Overview: Certificate Revocation Lists (CRLs)
    TLS and Cryptography Libraries Used by MariaDB
    TLS
    Secure Connections Overview: Certificate Revocation Lists (CRLs)
    TLS and Cryptography Libraries Used by MariaDB
    TLS
    TLS
    TLS
    TLS
    TLS and Cryptography Libraries Used by MariaDB
    TLS
    Secure Connections Overview: TLS Protocol Version Support
    TLS and Cryptography Libraries Used by MariaDB
    server certificate verification
    TLS
    mysql_old_password
    caching_sha2_password