Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

25.2.3.48. mysql_options()

int mysql_options(MYSQL *mysql, enum mysql_option option, const char *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.

mysql_options() should be called 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, then arg should point to the value of the integer.

Possible option values:

Option Argument Type Function
MYSQL_INIT_COMMAND char * Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting.
MYSQL_OPT_COMPRESS Not used Use the compressed client/server protocol.
MYSQL_OPT_CONNECT_TIMEOUT unsigned int * Connect timeout in seconds.
MYSQL_OPT_GUESS_CONNECTION Not used For an application linked against libmysqld, this allows the library to guess whether to use the embedded server or a remote server. “Guess” means that if the hostname is set and is not localhost, it uses a remote server. This behavior is the default. MYSQL_OPT_USE_EMBEDDED_CONNECTION and MYSQL_OPT_USE_REMOTE_CONNECTION can be used to override it. This option is ignored for applications linked against libmysqlclient.
MYSQL_OPT_LOCAL_INFILE optional pointer to uint If no pointer is given or if pointer points to an unsigned int != 0 the command LOAD LOCAL INFILE is enabled.
MYSQL_OPT_NAMED_PIPE Not used Use named pipes to connect to a MySQL server on NT.
MYSQL_OPT_PROTOCOL unsigned int * Type of protocol to use. Should be one of the enum values of mysql_protocol_type defined in mysql.h.
MYSQL_OPT_READ_TIMEOUT unsigned int * Timeout for reads from server (works currently only on Windows on TCP/IP connections).
MYSQL_OPT_RECONNECT my_bool * Enable or disable automatic reconnection to the server if the connection is found to have been lost. Reconnect has been off by default since MySQL 5.0.3; this option is new in 5.0.13 and provides a way to set reconnection behavior explicitly.
MYSQL_OPT_SET_CLIENT_IP char * For an application linked against linked against libmysqld (with libmysqld compiled with authentication support), this means that the user is considered to have connected from the specified IP address (specified as a string) for authentication purposes. This option is ignored for applications linked against libmysqlclient.
MYSQL_OPT_USE_EMBEDDED_CONNECTION Not used For an application linked against libmysqld, this forces the use of the embedded server for the connection. This option is ignored for applications linked against libmysqlclient.
MYSQL_OPT_USE_REMOTE_CONNECTION Not used For an application linked against libmysqld, this forces the use of a remote server for the connection. This option is ignored for applications linked against libmysqlclient.
MYSQL_OPT_USE_RESULT Not used This option is unused.
MYSQL_OPT_WRITE_TIMEOUT unsigned int * Timeout for writes to server (works currently only on Windows on TCP/IP connections).
MYSQL_READ_DEFAULT_FILE char * Read options from the named option file instead of from my.cnf.
MYSQL_READ_DEFAULT_GROUP char * Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.
MYSQL_REPORT_DATA_TRUNCATION my_bool * Enable or disable reporting of data truncation errors for prepared statements via MYSQL_BIND.error. (Default: disabled.)
MYSQL_SECURE_AUTH my_bool* Whether to connect to a server that does not support the password hashing used in MySQL 4.1.1 and later.
MYSQL_SET_CHARSET_DIR char* The pathname to the directory that contains character set definition files.
MYSQL_SET_CHARSET_NAME char* The name of the character set to use as the default character set.
MYSQL_SHARED_MEMORY_BASE_NAME char* Named of shared-memory object for communication to server. Should be same as the option --shared-memory-base-name used for the mysqld server you want to connect to.

Note that 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
connect-timeout Connect timeout in seconds. On Linux this timeout is also used for waiting for the first answer from the server.
compress Use the compressed client/server protocol.
database Connect to this database if no database was specified in the connect command.
debug Debug options.
disable-local-infile Disable use of LOAD DATA LOCAL.
host Default hostname.
init-command Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting.
interactive-timeout Same as specifying CLIENT_INTERACTIVE to mysql_real_connect(). See Section 25.2.3.51, “mysql_real_connect().
local-infile[=(0|1)] If no argument or argument != 0 then enable use of LOAD DATA LOCAL.
max_allowed_packet Max size of packet client can read from server.
multi-results Allow multiple result sets from multiple-statement executions or stored procedures.
multi-statements Allow the client to send multiple statements in a single string (separated by ‘;’).
password Default password.
pipe Use named pipes to connect to a MySQL server on NT.
protocol={TCP|SOCKET|PIPE|MEMORY} The protocol to use when connecting to the server.
port Default port number.
return-found-rows Tell mysql_info() to return found rows instead of updated rows when using UPDATE.
shared-memory-base-name=name Shared-memory name to use to connect to server (default is "MYSQL").
socket Default socket file.
user Default user.

Note that timeout has been replaced by connect-timeout, but timeout is still supported in MySQL 5.1.7-beta for backward compatibility.

For more information about option files, see Section 4.3.2, “Using Option Files”.

Return Values

Zero for success. Non-zero if you used an unknown option.

Example

MYSQL mysql;

mysql_init(&mysql);
mysql_options(&mysql,MYSQL_OPT_COMPRESS,0);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"odbc");
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 the client to use the compressed client/server protocol and read the additional options from the odbc section in the my.cnf file.


 
 
  Published under the terms of the GNU General Public License Design by Interspire