Spec-Zone .ru
спецификации, руководства, описания, API

21.8.7.49. mysql_options()

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

Description

Can be used to set extra connect options and affect behavior for a connection. This function may be called multiple times to set several options.

Call mysql_options() after mysql_init() and before mysql_connect() or mysql_real_connect().

The option argument is the option that you want to set; the arg argument is the value for the option. If the option is an integer, specify a pointer to the value of the integer as the arg argument.

The following list describes the possible options, their effect, and how arg is used for each option. Several of the options apply only when the application is linked against the libmysqld embedded server library and are unused for applications linked against the libmysqlclient client library. For option descriptions that indicate arg is unused, its value is irrelevant; it is conventional to pass 0.

The client group is always read if you use MYSQL_READ_DEFAULT_FILE or MYSQL_READ_DEFAULT_GROUP.

The specified group in the option file may contain the following options.

Option Description
character-sets-dir=path The directory where character sets are installed.
compress Use the compressed client/server protocol.
connect-timeout=seconds Connect timeout in seconds. On Linux this timeout is also used for waiting for the first answer from the server.
database=db_name Connect to this database if no database was specified in the connect command.
debug Debug options.
default-character-set=charset_name The default character set to use.
disable-local-infile Disable use of LOAD DATA LOCAL.
enable-cleartext-plugin Enable the mysql_clear_password cleartext authentication plugin.
host=host_name Default host name.
init-command=stmt Statement to execute when connecting to MySQL server. Automatically re-executed if reconnection occurs.
interactive-timeout=seconds Same as specifying CLIENT_INTERACTIVE to mysql_real_connect(). See Section 21.8.7.53, "mysql_real_connect()".
local-infile[={0|1}] If no argument or nonzero argument, enable use of LOAD DATA LOCAL; otherwise disable.
max_allowed_packet=bytes Maximum size of packet that client can read from server.
multi-queries, multi-results Enable multiple result sets from multiple-statement executions or stored procedures.
multi-statements Enable the client to send multiple statements in a single string (separated by ";").
password=password Default password.
pipe Use named pipes to connect to a MySQL server on Windows.
port=port_num Default port number.
protocol={TCP|SOCKET|PIPE|MEMORY} The protocol to use when connecting to the server.
return-found-rows Tell mysql_info() to return found rows instead of updated rows when usingUPDATE.
shared-memory-base-name=name Shared-memory name to use to connect to server.
socket=path Default socket file.
ssl-ca=file_name Certificate Authority file.
ssl-capath=path Certificate Authority directory.
ssl-cert=file_name Certificate file.
ssl-cipher=cipher_list Permissible SSL ciphers.
ssl-key=file_name Key file.
timeout=seconds Like connect-timeout.
user Default user.

timeout has been replaced by connect-timeout, but timeout is still supported in MySQL 5.7 for backward compatibility.

For more information about option files, see Section 4.2.3.3, "Using Option Files".

Return Values

Zero for success. Nonzero if you specify an unknown option.

Example

The following mysql_options() calls request the use of compression in the client/server protocol, cause options to be read from the [odbc] group of option files, and disable transaction autocommit mode:

MYSQL mysql;mysql_init(&mysql);mysql_options(&mysql,MYSQL_OPT_COMPRESS,0);mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"odbc");mysql_options(&mysql,MYSQL_INIT_COMMAND,"SET autocommit=0");if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0)){    fprintf(stderr, "Failed to connect to database: Error: %s\n",          mysql_error(&mysql));}

This code requests that the client use the compressed client/server protocol and read the additional options from the odbc section in the my.cnf file.