Page 1 of 1

How to connect via named pipes or shared memory?

Posted: 18.10.2011, 16:16
by mfurlend
I am trying to connect to my local Windows MYSQL DB via named pipes or shared memory, but I am getting a connection error.

SQL Error: Can't connect to MySQL server on 'localhost' (10061)

This is the relevant code:

Code: Select all

      conn := TZConnection.Create(nil);
      conn.Protocol := 'mysql-5';
      conn.HostName := 'localhost';
      conn.Port := -1;
      conn.Database := 'data';
      conn.User := 'root';
      conn.Password := 'xxxx';

      conn.Properties.Add('protocol=memory');
      conn.Properties.Add('shared-memory-base-name=MYSQL');
      conn.Connect; 


And for named pipes I tried:

Code: Select all

conn.Properties.Add('protocol=pipes');
And

Code: Select all

conn.Properties.Add('MYSQL_OPT_NAMED_PIPE');
The my.ini file looks like this:

[mysqld]
#log-error = "C:\errors.txt"
#port = 3306
skip-networking
enable-named-pipe
socket=mysql
shared_memory = ON
shared-memory-base-name=MYSQL
#general-log

I can connect via Navicat to the DB through named pipes just fine.
Please help!

Posted: 30.10.2011, 21:12
by mdaems
I never used named pipes. But I just did some mysql doc reading.

Seems to me from http://dev.mysql.com/doc/refman/5.5/en/ ... tions.html that you can use
- MYSQL_READ_DEFAULT_FILE (argument type: char *) : Read options from the named option file instead of from my.cnf.
- MYSQL_READ_DEFAULT_GROUP (argument type: char *): Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.
These settings make the setings in your ini file the default for the connetion.

However, looking a little further in the zeoslib code (ZPlainMysqlConstants.pas and ZDbcMysql.pas) makes me think

Code: Select all

conn.Properties.Add('MYSQL_OPT_NAMED_PIPE');
conn.Properties.Add('MYSQL_OPT_PROTOCOL=<number>');
conn.Properties.Add('MYSQL_SHARED_MEMORY_BASE_NAME=MYSQL');
may do the job. Not sure if the code works for the protocol numerical option though. (See code in procedure TZMySQLConnection.Open;)
The protocol number should correspond to one of following options in the mysql.h header file:

Code: Select all

enum mysql_protocol_type 
{
  MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
  MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
};
Hope this helps you a little.

Mark