mysql_options — Set options

int mysql_options(MYSQL * mysql,
                  enum mysql_option,
                  const void * arg);

Used to set extra connect options and affect behavior for a connection.

This function may be called multiple times to set several options. mysql_options() should be called after mysql_init() and before mysql_real_connect().

Parameters

mysql

A mysql handle, which was previously allocated by mysql_init() or mysql_real_connect().

mysql_option

The option you want to set.

MYSQL_OPT_CONNECT_TIMEOUT

Connect time out in seconds.

unsigned int timeout= 5;
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&timeout);                   
                   

This value will be passed as an unsigned int * parameter

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_options(mysql, MYSQL_OPT_COMPRESS, NULL);                   
                   
MYSQL_OPT_NAMED_PIPE

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

mysql_options(mysql, MYSQL_OPT_NAMED_PIPE, NULL);                   
                   
MYSQL_OPT_LOCAL_INFILE

Enable or disable use of LOAD DATA LOCAL INFILE

mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, NULL);        /* disable */                  
mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, (void *)"1"); /* enable */                  
                   
MYSQL_INIT_COMMAND

Command(s) which will be executed when connecting and reconnecting to the server

mysql_options(mysql, MYSQL_INIT_COMMAND, (void *)"CREATE TABLE ...");
                   
MYSQL_READ_DEFAULT_FILE

Read options from named option file instead of my.cnf

mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, (void *)"./my_conf.cnf");
                   
MYSQL_READ_DEFAULT_GROUP

Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.

mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, (void *)"my_section");
                   
MYSQL_SET_CHARSET_NAME

Specify the default character set for the connection.

mysql_options(mysql, MYSQL_SET_CHARSET_NAME, (void *)"utf8");
                   
MYSQL_OPT_RECONNECT

Enable or disable automatic reconnect.

mysql_options(mysql, MYSQL_OPT_RECONNECT, NULL);        /* disable */                  
mysql_options(mysql, MYSQL_OPT_RECONNECT, (void *)"1"); /* enable */                  
                   
MYSQL_OPT_PROTOCOL

Specify the type of client/server protocol. Possible values are: MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, MYSQL_PROTOCOL_PIPE.

enum mysql_protocol_type prot_type= MYSQL_PROTOCOL_SOCKET;
mysql_options(mysql, MYSQL_OPT_PROTOCOL, (void *)&prot_type);
                   
MYSQL_OPT_READ_TIMEOUT

Specifies the timeout in seconds for reading packets from server.

unsigned int timeout= 5;
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (void *)&timeout);                   
                   
MYSQL_OPT_WRITE_TIMEOUT

Specifies the timeout in seconds for sending packets to server.

unsigned int timeout= 5;
mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (void *)&timeout);                   
                   
MYSQL_REPORT_DATA_TRUNCATION

Enable or disable reporting data truncation errors for prepared statement.

mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, NULL);        /* disable */                  
mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (void *)"1"); /* enable */                  
                   
MYSQL_OPT_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

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_options(mysql, MYSQL_OPT_PROGRESS_CALLBACK, (void *)report_progress);                  
                   
arg

The value for the option

Return value

Zero on success, non zero if an error occured (invalid option or value)

[Note]

If MYSQL_READ_DEFAULT_FILE is specified the [client] section will be always processed.

See also

mysql_init(), mysql_real_connect()