Bug #41911 mysql_options doesn't work
Submitted: 7 Jan 2009 3:22 Modified: 11 Jan 2009 15:00
Reporter: xiao ke Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.0 OS:Windows (sp2)
Assigned to: CPU Architecture:Any

[7 Jan 2009 3:22] xiao ke
Description:
I'm using the mysql_option to set the timeout, but it is not working at all. If the
server is down, mysql_real_connect is waiting very long(for about 20s) before returning.
 The time is about 20 seconds more or less, may you tell me a method to slove this problem?
 I want this time is about 5 seconds

 I tried such codes as follows,
 unsigned int wait_timeout = 5;
 mysql_options(m_conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&wait_timeout);

 but I can't get my aim, please help me to slove this problem, if you can give me a code-example, I'll appreciate it.

How to repeat:
MYSQL* m_conn = NULL;
mysql_init(m_conn);
unsigned int wait_timeout = 3;	
mysql_options(m_conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&wait_timeout);
mysql_real_connect(m_conn,host,"root","root","csfnode",3306,NULL,CLIENT_MULTI_STATEMENTS);

The host is down, the return time is about 20 seconds, not 3 seconds.

Suggested fix:
maybe can improve funciton connect, at least, give the rights to users to set the connect_timeout.
[7 Jan 2009 16:52] MySQL Verification Team
Thank you for the bug report. Could you please use the mysql_option with MYSQL_READ_DEFAULT_FILE and then in the configuration file setup the value
of interactive-timeout to the same value of wait_timeout. Thanks in advance.
[8 Jan 2009 8:05] xiao ke
thanks for your apply, but I think you may misunderstand my means, in your suggestion, I think the method you give me is to slove the problem "client disconnect from the server for a longtime which default value is 28800 seconds"

My problem is how to set the time used to judge the return-time for the "mysql_real_connect", that is to say, what is the value of time for "mysql_real_connect" return ? I think the value is 20 second, I want to know is there a method to change the value? 

for example,OS-Microsoft Windows (sp2) in the if the server is down, I ues a client to connect the server, must I wait for 20 seconds? can you provide a methond to set this value?

MYSQL* m_conn = NULL;
mysql_init(m_conn);
unsigned int wait_timeout = 3;	
mysql_options(m_conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&wait_timeout);
mysql_real_connect(m_conn,host,"root","root","csfnode",3306,NULL,CLIENT_MULTI_STATEMENTS);

I want to set the connect-timeout in the windows, in the OS-unix;
the flowing code

mysql_options(m_conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&wait_timeout);

works well, but in the windows, it doesn't work at all. I want to find a method to slove this problem

Looking froward to your apply

thanks.
[11 Jan 2009 15:00] Sveta Smirnova
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Duplicate of bug #36225