Author Topic: how to connect to mariadb 12.3.2?  (Read 820 times)

SA.Blackmon

  • Jr. Member
  • **
  • Posts: 62
  • Just an old retired guy practicing what he enjoys.
how to connect to mariadb 12.3.2?
« on: July 22, 2026, 11:51:23 pm »
mariadb 12.3.2
lazarus 4.8 32 bit
libmysql.dll 32 bit

I now have libmysql.dll in windows\system32 and my executable directory but kept getting the libmysql.dll not found error. I did attempt and believe I am correct that the bitness of the components is the same, namely 32 bit.

So I gave that up as a lost cause.

So, am trying to use the TODBCConnector and get a message that says the data source name not found and no default driver specified.

My two questions are:
* what datasource name is the component looking for and how do I specify it once I've found it.
-and-
* same sort of thing about the default driver.
Thank you for your help,
Sherril

Zvoni

  • Hero Member
  • *****
  • Posts: 3519
Re: how to connect to mariadb 12.3.2?
« Reply #1 on: July 23, 2026, 09:46:55 am »
It has nothing to do with TODBCConnector or the Native class.

It certainly IS a Bitness-Problem

and for the upteemth time:
Windows/System32 IS NOT the 32-Bit directory. It's the 64-Bit-Directory
Windows/SysWOW64 IS the 32-Bit Directory

Though no idea about the search-order.

dll-bitness must match the Bitness of the Project-Target, NOT the used Lazarus/FPC-Bitness.
It only has to match Lazarus/FPC-Bitness, if you use visual components and want to establish connection in DESIGN-TIME
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 19805
  • Glad to be alive.
Re: how to connect to mariadb 12.3.2?
« Reply #2 on: July 23, 2026, 10:38:25 am »
@Zvoni
Are you back to answer silly questions too ?  :-X
Yes, and that disturbes both of us (not only us).
Here's a function that can read what bitness the dll is:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. uses
  3.   Classes, SysUtils, Windows;
  4.  
  5. function GetDLLBitness(const AFileName: string): string;
  6. const
  7.   // Constants for PE header parsing
  8.   IMAGE_DOS_SIGNATURE = $5A4D;      // 'MZ'
  9.   IMAGE_NT_SIGNATURE = $4550;       // 'PE' + two null bytes
  10.   IMAGE_FILE_MACHINE_I386 = $014c;  // 32-bit
  11.   IMAGE_FILE_MACHINE_AMD64 = $8664; // 64-bit
  12.   IMAGE_FILE_DLL = $2000;           // DLL flag
  13. var
  14.   FS: TFileStream;
  15.   DosHeader: packed record
  16.     e_magic: Word;
  17.     e_lfanew: LongInt;
  18.   end;
  19.   NtSignature: LongWord;
  20.   FileHeader: packed record
  21.     Machine: Word;
  22.     NumberOfSections: Word;
  23.     TimeDateStamp: LongWord;
  24.     PointerToSymbolTable: LongWord;
  25.     NumberOfSymbols: LongWord;
  26.     SizeOfOptionalHeader: Word;
  27.     Characteristics: Word;
  28.   end;
  29.   IsDLL: Boolean;
  30. begin
  31.   Result := 'Error or unknown file';
  32.   FS := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
  33.   try
  34.     // Read DOS header
  35.     if FS.Size < SizeOf(DosHeader) then
  36.       Exit;
  37.     FS.ReadBuffer(DosHeader, SizeOf(DosHeader));
  38.    
  39.     // Validate DOS signature ('MZ')
  40.     if DosHeader.e_magic <> IMAGE_DOS_SIGNATURE then
  41.       Exit;
  42.    
  43.     // Position to PE header and read signature
  44.     if FS.Size < DosHeader.e_lfanew + SizeOf(NtSignature) then
  45.       Exit;
  46.     FS.Position := DosHeader.e_lfanew;
  47.     FS.ReadBuffer(NtSignature, SizeOf(NtSignature));
  48.    
  49.     // Validate PE signature ('PE')
  50.     if NtSignature <> IMAGE_NT_SIGNATURE then
  51.       Exit;
  52.    
  53.     // Read the IMAGE_FILE_HEADER
  54.     if FS.Size < FS.Position + SizeOf(FileHeader) then
  55.       Exit;
  56.     FS.ReadBuffer(FileHeader, SizeOf(FileHeader));
  57.    
  58.     // Check if it's a DLL [citation:11]
  59.     IsDLL := (FileHeader.Characteristics and IMAGE_FILE_DLL) = IMAGE_FILE_DLL;
  60.     if not IsDLL then
  61.     begin
  62.       Result := 'File is not a DLL';
  63.       Exit;
  64.     end;
  65.    
  66.     // Determine bitness based on Machine field
  67.     case FileHeader.Machine of
  68.       IMAGE_FILE_MACHINE_I386: Result := '32-bit DLL';
  69.       IMAGE_FILE_MACHINE_AMD64: Result := '64-bit DLL';
  70.     else
  71.       Result := 'DLL for unknown architecture';
  72.     end;
  73.   finally
  74.     FS.Free;
  75.   end;
  76. end;
  77. begin
  78. end.
Use that to check if you have the correct libraries.
 (or use the objdump utility that comes with FreePascal)
[edit] my code needs a minor fix. will replace it later. I am occupied.
« Last Edit: July 23, 2026, 10:53:01 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

Zvoni

  • Hero Member
  • *****
  • Posts: 3519
Re: how to connect to mariadb 12.3.2?
« Reply #3 on: July 23, 2026, 12:57:58 pm »
@Zvoni
Are you back to answer silly questions too ?  :-X

I'm a bit (now there is that word again) bored right now :D

Nevermind that i found something absolutely hilarious this morning on facebook, that has me grinning like a loon the whole day.
(It has to do with: Airplanes, Spain, WorldCup, Argentina)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

SA.Blackmon

  • Jr. Member
  • **
  • Posts: 62
  • Just an old retired guy practicing what he enjoys.
Re: how to connect to mariadb 12.3.2? (Windows 11)
« Reply #4 on: August 06, 2026, 11:59:50 pm »
I am still flumoxxed by trying to connect.

I am getting a message on attempted connect using any TMySqlConnection north of version 5.5 that says the connection can not work with the install MySql client version expected ( ) got 5.5.9.

I did a recursive ls across my entire hard drive for libm*.dll. Those I found that were obviously not current I deleted and the issue persists.

I have no idea where to look now.

Please give me suggestions (without the snarkiness, please).
Thank you for your help,
Sherril

heejit

  • Sr. Member
  • ****
  • Posts: 251
Re: how to connect to mariadb 12.3.2?
« Reply #5 on: August 07, 2026, 06:44:18 am »
try this :
    Result := mysql57conn.TMySQL57Connection.Create(nil);
    mysql57conn.TMySQL57Connection(Result).SkipLibraryVersionCheck:=True;

« Last Edit: August 07, 2026, 07:00:42 am by heejit »

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1319
Re: how to connect to mariadb 12.3.2?
« Reply #6 on: August 07, 2026, 12:03:45 pm »
I note you're initial error was getting "cannot find dll" error though, not cannot load dll.   How are you setting the dll location?

For MariaDB, I'm using ZeosDB.  The DriverDir[] call is my own code and simply ensures I'm loading the correct bitness DLL, just esure you're setting the full path to the dll

Code: Pascal  [Select][+][-]
  1.   FConnection := TZConnection.Create(Application.MainForm);
  2.   FConnection.Protocol := 'mysql';
  3.   FConnection.LibraryLocation := DriverDir['mysql'] + 'libmysql.dll';  

For SQLDB stuff, I use InitialiseDBLib.  Example below:
Code: Pascal  [Select][+][-]
  1.   sDriver := DriverDir['dblib'];
  2.  
  3.   If DirectoryExists(sDriver, False) Then
  4.   Begin
  5.     AddToEnvironmentPath(sDriver);
  6.     InitialiseDBLib('dblib.dll');
  7.   End;    
 

And this uses

Code: Pascal  [Select][+][-]
  1. Procedure SetEnvVar(Const Name, Value: String);
  2. Begin
  3.   {$IFDEF UNIX}
  4.   // Use FpSetEnv, expects 'NAME=VALUE'
  5.   FpSetEnv(PChar(Name + '=' + Value));
  6.   {$ENDIF}
  7.  
  8.   {$IFDEF WINDOWS}
  9.   // SetEnvironmentVariableA (ANSI version)
  10.   SetEnvironmentVariable(PChar(Name), PChar(Value));
  11.   {$ENDIF}
  12. End;
  13.  
  14. Procedure AddToEnvironmentPath(AFolder: String);
  15. Var
  16.   sCurrentPath: String;
  17. Begin
  18.   sCurrentPath := SysUtils.GetEnvironmentVariable('PATH');
  19.   If sCurrentPath = '' Then
  20.     SetEnvVar('PATH', AFolder)
  21.   Else
  22.     SetEnvVar('PATH', AFolder + ';' + sCurrentPath);
  23. End;  
  24.  
« Last Edit: August 07, 2026, 12:55:13 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  How to use the forum:  https://wiki.lazarus.freepascal.org/Forum

cal

  • Newbie
  • Posts: 1
Re: how to connect to mariadb 12.3.2?
« Reply #7 on: August 07, 2026, 12:43:27 pm »
You also need "libmariadb.dll" in a place where windows can find it for connecting to mariaDB.
It is where you installed MariaDb. On my computer in "C:\Program Files\MariaDB 10.4\lib" and should be copied. (I'm using MariaDB version 10.4)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1319
Re: how to connect to mariadb 12.3.2?
« Reply #8 on: August 07, 2026, 12:44:23 pm »
I am still flumoxxed by trying to connect.

You say you're using MariaDB 12.3.2

Why are you using libmysql.dll?   I note my instance of MariaDB (10.11.8 ) ship with libmariadb.dll for connection instead.

Just try point to that DLL

Code: Pascal  [Select][+][-]
  1. uses
  2.   mysql80conn;
  3.  
  4. begin
  5.   InitialiseDBLib('C:\MyApp\libmariadb.dll');
  6.  
  7.   MySQL80Connection1.HostName := 'localhost';
  8.   MySQL80Connection1.DatabaseName := 'mysql';
  9.   MySQL80Connection1.UserName := 'user';
  10.   MySQL80Connection1.Password := 'password';
  11.   MySQL80Connection1.Connected := True;
  12. end;

Update: I'm troubleshooting this - not working for me either.

Update2: I'm now reproducing OP's reported issue, just with different version numbering.  Which makes sense, I'm using an older DLL.
I need to recompile fpc with debug info.  Unfortunately, I'm out of time.  I'll try this tomorrrow.

But this is all bringing back memories for me.  I couldn't get this to work in the past either.  It's why I use ZeosDB for MariaDB.  I really should document these decisions.

My code in case anyone wants to pick this up:
Code: Pascal  [Select][+][-]
  1. Uses
  2.   mysql80conn, mysql80dyn, sqldb;
  3.  
  4.   {$R *.lfm}
  5.  
  6.   { TForm1 }
  7.  
  8.  
  9. Procedure TForm1.Button1Click(Sender: TObject);
  10. Var
  11.   Conn: TMySQL80Connection;
  12.   Tran: TSQLTransaction;
  13. Begin
  14.   Conn := nil;
  15.   Tran := nil;
  16.  
  17.   Try
  18.     InitialiseMysql('B:\Apps\Dev\UniserverZ_mariaDB\core\mysql\bin\libmariadb.dll');
  19.  
  20.     Conn := TMySQL80Connection.Create(nil);
  21.     Tran := TSQLTransaction.Create(nil);
  22.  
  23.     Conn.Transaction := Tran;
  24.     Tran.DataBase := Conn;
  25.  
  26.     Conn.HostName := 'localhost';
  27.     Conn.DatabaseName := 'mysql';
  28.     Conn.UserName := 'root';
  29.     Conn.Password := 'password';
  30.     Conn.Port := 3306;
  31.  
  32.     Caption := Conn.ClientInfo;  // debug only.  I'm getting 3.3.10
  33.  
  34.     Conn.SkipLibraryVersionCheck := True;  // comment this out and get a version clash.  Uncomment this and get "could not connect"
  35.  
  36.     Conn.Open;
  37.  
  38.     ShowMessage('Connected successfully');
  39.  
  40.     Conn.Close;
  41.  
  42.   Except
  43.     on E: Exception Do
  44.       ShowMessage(E.ClassName + LineEnding + E.Message);
  45.   End;
  46.  
  47.   Tran.Free;
  48.   Conn.Free;
  49. End;  

« Last Edit: August 07, 2026, 01:10:28 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  How to use the forum:  https://wiki.lazarus.freepascal.org/Forum

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1319
Re: how to connect to mariadb 12.3.2?
« Reply #9 on: August 07, 2026, 01:30:59 pm »
Just dropping this here as a bookmark for when I get back to this tomorrow...
https://forum.lazarus.freepascal.org/index.php?topic=62973.0
Lazarus Trunk/FPC latest fixes on Windows 11
  How to use the forum:  https://wiki.lazarus.freepascal.org/Forum

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1319
Re: how to connect to mariadb 12.3.2?
« Reply #10 on: August 08, 2026, 12:25:31 pm »
New day, previous code works just fine - turns out I had a firewall issue.   Once I resolved that, my last code posted worked as is.  I needed the Conn.SkipLibraryVersionCheck := True; line.

Code: Pascal  [Select][+][-]
  1. Uses
  2.   mysql80conn, mysql80dyn, sqldb;
  3.  
  4.   {$R *.lfm}
  5.  
  6.   { TForm1 }
  7.  
  8.  
  9. Procedure TForm1.Button1Click(Sender: TObject);
  10. Var
  11.   Conn: TMySQL80Connection;
  12.   Tran: TSQLTransaction;
  13. Begin
  14.   Conn := nil;
  15.   Tran := nil;
  16.  
  17.   Try
  18.     // adjust accordingly
  19.     // Do not use InitialiseDBLib (which is why my historical code wasn't working)
  20.     InitialiseMySql('B:\Apps\Dev\UniserverZ_mariaDB\core\mysql\bin\libmariadb.dll');
  21.  
  22.     Conn := TMySQL80Connection.Create(nil);
  23.     Tran := TSQLTransaction.Create(nil);
  24.  
  25.     Conn.Transaction := Tran;
  26.     Tran.DataBase := Conn;
  27.  
  28.     Conn.HostName := 'localhost';
  29.     Conn.DatabaseName := 'mysql';
  30.     Conn.UserName := 'root';
  31.     Conn.Password := 'password';
  32.     Conn.Port := 3306;
  33.  
  34.     Conn.SkipLibraryVersionCheck := True;
  35.  
  36.     Conn.Open;
  37.  
  38.     ShowMessage('Connected successfully');
  39.  
  40.     Conn.Close;
  41.  
  42.   Except
  43.     on E: Exception Do
  44.       ShowMessage(E.ClassName + LineEnding + E.Message);
  45.   End;
  46.  
  47.   Tran.Free;
  48.   Conn.Free;
  49. End;
« Last Edit: August 08, 2026, 12:30:02 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  How to use the forum:  https://wiki.lazarus.freepascal.org/Forum

eldonfsr

  • Hero Member
  • *****
  • Posts: 612
Re: how to connect to mariadb 12.3.2?
« Reply #11 on: August 10, 2026, 07:02:22 pm »
CHECK THIS POST COULD YOU HAVE SAME PROBLEM AS  ME NEW VERSIONS OF MYSQL REQUIRE MORE DLLS TO WORK

https://forum.lazarus.freepascal.org/index.php/topic,74506.msg587754.html#msg587754

I GO FOLDER WHERE MYSQL SERVER INSTALLED AND COPY DLLS TO MY FOLDER  AND APP WORKS.

 

eldonfsr

  • Hero Member
  • *****
  • Posts: 612
Re: how to connect to mariadb 12.3.2?
« Reply #12 on: August 10, 2026, 07:38:05 pm »
Here link you can download small app with dlls for mysql

https://mega.nz/file/hrhXSJ5A#Jw3HFR5qk_th0v3dAW1yBrqIFagSJWR3Q-TM7cvhfKI

could be this help to you...

 

TinyPortal © 2005-2018