Bug #60405 mysql_real_connect fails when trying to use shared memory
Submitted: 9 Mar 2011 17:13 Modified: 22 Mar 2011 19:12
Reporter: Attila Bódy Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / C Severity:S2 (Serious)
Version:6.0.2 OS:Microsoft Windows (windows 7 enterprise N)
Assigned to: CPU Architecture:Any
Tags: shared-memory
Triage: Needs Triage: D2 (Serious)

[9 Mar 2011 17:13] Attila Bódy
Description:
MySQL server configured to support shared memory connection, mysql "factroy" client connects without any problem using "--protocol=memory" option.

When we try to connect to the server using shared memory (either specifying "localhost" or NULL as host string and/or setting MYSQL_OPT_PROTOCOL to MYSQL_PROTOCOL_MEMORY calling mysql_options call mysql_real_connect fails, then mysql_error() returns "Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0" message.
The connection builds up successfully (using TCP/IP) if we use 127.0.0.1 as host string (and not forcing the connection to use shared memory)

mysql_real_connect(m_mysql,"localhost",user,password,database,0,NULL,0) fails
mysql_real_connect(m_mysql,"127.0.0.1",user,password,database,3306,NULL,0) succeeds (using TCP/IP)

We experienced similar behavior when tried to connect using named pipe

How to repeat:
see description
[9 Mar 2011 19:15] Miguel Solorzano
Could you please provide your C test case?. Thanks in advance.
[10 Mar 2011 11:03] Attila Bódy
#include <winsock2.h>
#include <windows.h>
#include "mysql.h"

#pragma comment( lib, "libmysql" )

int _tmain(int argc, _TCHAR* argv[])
{
	MYSQL	*mysql( mysql_init( NULL ) );
	const char	*strerr;

	if( mysql_real_connect(
		mysql, "localhost",
		"user", "password",
		"testdb",
		0, NULL, 0
	) != mysql ) {
		strerr = mysql_error( mysql );
	}

	mysql_close( mysql );

	return 0;
}

the above fails with "Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0" message.

if I replace "localhost" to "127.0.0.1" the connection succeeds (but uses TCP/IP)

Some additional info:
-----------------------------------------------------------------------------
C:\SDKs\MySQL Connector C 6.0.2 64bit\bin>mysql_client_test.exe --host=localhost
 --user=user --password=password

#####################################
client_connect
#####################################

 Establishing a connection to 'localhost' ...
 [MySQL][2013] Lost connection to MySQL server at 'waiting for initial communica
tion packet', system error: 2

 Check the connection options using --help or -?
-----------------------------------------------------------------------------
mysql --protocol=memory --user=user --password=password

still connects flawlessly anyway
[10 Mar 2011 15:27] Attila Bódy
If we run mysqld from the console (instead of running it as service), SHM connection builds up without any problem. Running as service under a real user account instead of localsystem, does not help .
[10 Mar 2011 15:43] Peter Laursen
Interesting.  Services running under 'localsystem' account have several restrictions.  For instance they cannot access shares using the mapped drive letter.

Did you try 'networkservice' account? No guarantee, but worth trying (and I believe it is what SQL Server does).

Peter
(not a MySQL person)
[10 Mar 2011 16:52] Attila Bódy
It cannot be started with networkservice user as it has no acces to files on the default install path. I tried two usert (created user MySQL just for this purpose which i made sure has rights for the necessary files) but there is no luck except we start mysqld using a cmd shell in the same session we try to connect via SHM.
[22 Mar 2011 19:12] Miguel Solorzano
Thank you for the bug report.

C:\DBS>5.1\bin\bug60405
Error: Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0