Bug #65433 Can't connect to MySQL server on '<hostname>' (111) error is getting shown
Submitted: 27 May 2012 11:47 Modified: 23 Aug 2012 15:03
Reporter: Kunal Verma Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:5.1.47 OS:Any (Linux 64bit)
Assigned to: CPU Architecture:Any
Tags: 111, error no=2003

[27 May 2012 11:47] Kunal Verma
Description:
Case 1:
When I connect to remote mysql server i.e. mysql server is not on localhost using installed mysql command-line, connectionn is getting established. Used command -line: mysql -u<user name> -p<password> -h<host name> -P 3306 <database name> 

Hostname is not localhost, it is valid hostname e.g. mymachine.pc.sth.com

Case 2:
I have an application which uses mysql_real_connect statement with following arguments after calliing mysql_init

my_conn=mysql_real_connect(my_data_conn,mhost,muser,passwd,mdb,mport,NULL,0);

On running above program connection is getting successful. In this case also mysql server is installed on remote server i.e. mysql server is not on localhost and I am providing valid hostname.

From above two successful connections using mysql_real_connect, it is evident that there is no issue with tcp/ip connection using 3306 port with the remote mysql server.

Case 3:
I have third custom mysql client program. I am running this custom command-line as below:

lax93t01> ./mysql_client -u <username> -pw <password> -h <valid hostname> -p 3306 -d <database name>
My program is printing below error:

error no=2003, error message=Can't connect to MySQL server on 'valid hostname' (111)

Below is variable declaration and mysql_real_connect that I am using in custom mysql command-line program i.e. mysql_client

int client_flag = 0;
char* socket = NULL;

temp = mysql_real_connect(mysql_handle_conn,user_input_conn_parms->hostname,
                               user_input_conn_parms->userid,
                               user_input_conn_parms->password,
                               user_input_conn_parms->databasename,
                               (int) *(user_input_conn_parms->port),
                               socket,
                               client_flag);

Is there any option to be set on client side but if it is the case why case 1 and case 2 are getting successful is it not that error is coming from mysql server? why mysql server allows connection using mysql commnad-line and one appliocation but third application is showing this error? 

How to repeat:
Run Custom mysql command-line executable of case 3 (from description)
[27 May 2012 12:15] Valeriy Kravchuk
We're sorry, but the bug system is not the appropriate forum for asking help on using MySQL products. Your problem is not the result of a bug.

Support on using our products is available both free in our forums at http://forums.mysql.com/ and for a reasonable fee direct from our skilled support engineers at http://www.mysql.com/support/

Thank you for your interest in MySQL.
[27 May 2012 17:39] Kunal Verma
Thanks, I will let you know what was the actual issue when I look more into it.
[7 Aug 2012 15:24] lee lei
I got the same promblem...
Have you fixed it?
[23 Aug 2012 15:03] Kunal Verma
It was related with storing number in string variable. While debugging I found that variable for port number was different number than 3306 due to it. It is fixed now