//函数原型描述

const char *passwd, const char *db, unsigned int port, const char *unix_socket,
unsigned long client_flag)




running on host. mysql_real_connect() must complete successfully before you can
execute any other API functions that require a valid MYSQL connection handle structure.






calling mysql_real_connect() you must call mysql_init() to initialize the MYSQL
structure. You can change a lot of connect options with the mysql_options() call.
See Section 17.2.3.47, “mysql_options()”.



string "localhost", a connection to the local host is assumed. If the OS supports sockets
(Unix) or named pipes (Windows), they are used instead of TCP/IP to connect to the server.



string "", the current user is assumed. Under Unix, this is the current login name. Under
Windows ODBC, the current username must be specified explicitly. See Section 18.1.9.2,
“Configuring a MyODBC DSN on Windows”.



in the user table for the user that have a blank (empty) password field are checked for a
match. This allows the database administrator to set up the MySQL privilege system in
such a way that users get different privileges depending on whether they have specified
a password.


password encryption is handled automatically by the client API.



to this value.



that the host parameter determines the type of the connection.



be used. Note that the host parameter determines the type of the connection.


flags to enable certain features:
//上面描述了五个参数的主要取值,MYSQL *为mysql_init函数返回的指针,host为null或 // localhost时链接的是本地的计算机,当mysql默认安装在unix(或类unix)系统中,root账户是没// 有密码的,因此用户名使用root,密码为null,当db为空的时候,函数链接到默认数据库,在进行 // mysql安装时会存在默认的test数据库,因此此处可以使用test数据库名称,port端口为0,使用 // unix连接方式,unix_socket为null时,表明不使用socket或管道机制,最后一个参数经常设置为0



changed rows.

reserved words.

seconds) of inactivity before closing the connection. The client's session wait_timeout
variable is set to the value of the session interactive_timeout variable.


statements in a single string (separated by ‘;’). If this flag is not set,
multiple-statement execution is disabled. Added in MySQL 4.1.

sets from multiple-statement executions or stored procedures. This is automatically
set if CLIENT_MULTI_STATEMENTS is set. Added in MySQL 4.1.

ODBC. It causes the parser to generate an error if you use that syntax, which is useful
for trapping bugs in some ODBC programs.

ODBC-friendly.

application programs; it is set internally in the client library. Instead, use
mysql_ssl_set() before calling mysql_real_connect().


than from an explicit value in the mysql_real_connect() call. To do this, call
mysql_options() with the MYSQL_READ_DEFAULT_FILE or MYSQL_READ_DEFAULT_GROUP option
before calling mysql_real_connect(). Then, in the mysql_real_connect() call, specify
the “no-value” value for each parameter to be read from an option file:










the mysql_real_connect() call cannot be overridden in an option file, because the empty
string indicates explicitly that the MySQL account must have an empty password.)











indicated in the descriptions given earlier in this section.




was unsuccessful. For a successful connection, the return value is the same as the value
of the first parameter.
// 返回值:当连接成功时,返回MYSQL连接句柄,失败,返回NULL。当成功时,返回值与第一个参数值是// 相同的。






































library that uses a different protocol version. This can happen if you use a very old
client library to connect to a new server that wasn't started with the --old-protocol
option.




















the server or if the server died while executing the init-command.


mysql_real_connect(mysql,"localhost","root",NULL,"test",0,NULL,0);
判断是否出错,出错调用mysql_error()
函数显示出错信息,或使用mysql_errno()函数获取出错代号。