Search code examples
mysqldelphishared-memorylazaruszeos

ZeosLib with MYSQL's shared memory protocol?


I started up my local MYSQL server with the shared memory protocol turned on. How can I connect to my server with ZeosLib? Where do I specify that it is using shared-memory?

I am using Lazarus(freepascal), although the directions would be the same for Delphi (probably).


Solution

  • Even if the TZConnection has no connection string property you can set the additional connection parameters in TZConnection.Properties.

    I presume you run your MySQL server this way

    mysqld --skip-networking --shared_memory=1 --shared-memory-base-name='MyMemoryDB'
    

    To enable your shared memory connection you might try to add the following configuration lines into the property TZConnection.Properties at design time in Object Inspector. Note that the protocol must be set as it is and shared-memory-base-name to the same value as you used in the command line parameter. The default value is MYSQL so if you omit the parameter in command line then you should change the following MyMemoryDB values to MYSQL.

    So in TZConnection.Properties property try to add these two lines

    protocol=memory
    shared-memory-base-name=MyMemoryDB
    

    or at runtime in the TZConnection.BeforeConnect event handler use

    procedure TForm1.ZConnection1BeforeConnect(Sender: TObject);
    begin
      ZConnection1.Properties.Add('protocol=memory');
      ZConnection1.Properties.Add('shared-memory-base-name=MyMemoryDB');
    end;
    

    Hope this will help you somehow. I haven't tested it because I don't have the proper environment.