Delphi: How to check if MySQL is installed on windows machine Delphi: How to check if MySQL is installed on windows machine mysql mysql

Delphi: How to check if MySQL is installed on windows machine


Regarding MySQL server:

  1. As @Shirish11 sayd, you can check HKLM\SOFTWARE\MySQL AB. But that does not guarantee anything, as this registry key is optional. MySQL really does not require any "complex" installation procedure, like SQL Server. You can download MySQL as an installer, as just a ZIP archive. In last case the registry key will be not created. The similar with services. Using mysqld.exe --install Kitty --defaults-file=c:\mysql.cfg command line you can create MySQL service with Kitty name. Or even a service may be not created at all.
  2. The MySQL server may be installed not locally, but on a different host. And be administrated by a dedicated DBA. So, you may not need to check / install server at all. Just not your task. If your application is going to install a local server, which will be used only by "this" workstation, then use MySQL Embedded.
  3. In general, you should ask the user about MySQL installation, eg "Do you have MySQL server installed ?". And if user answers "yes", then you can ask him for login parameters (host, port, database, user name, password). If not, then you can suggest him to download it and install, to avoid licensing issues. Because you have to have a license, purchased from Oracle, to distribute the MySQL Server installer with your software.

Regarding MySQL client:

  1. There is no other signs, that libmysql.dll is "installed", than the libmysql.dll presence. You can check for libmysql.dll at Windows folder, at PATH folders. More simple - you can always put it with your EXE.
  2. If you are using dbExpress, then you should use specific libmysql.dll version, supported by EMBT dbExpress driver. So, again, better to put it with your EXE.
  3. See note (3) regarding server licensing. It applies to client too.


Check for this registry entry for MySQL if present
HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB
If you have MySQL installed then this entry should be present.

If you need some thing more, then check for the service if its present

    function ServiceIsPresent(sMachine, sService: PChar): Boolean;    var      SCManHandle, SvcHandle: SC_Handle;    begin      // Open service manager handle.      SCManHandle := OpenSCManager(sMachine, nil, SC_MANAGER_CONNECT);      if (SCManHandle > 0) then      begin        SvcHandle := OpenService(SCManHandle, sService, SERVICE_QUERY_STATUS);        // if Service installed        if (SvcHandle > 0) then          begin               Result := True;            CloseServiceHandle(SvcHandle);          end;        else            Result := False;         CloseServiceHandle(SCManHandle);      end;    end;

function call

  ServiceGetStatus(nil,'MySQL');

I have picked up this service name from my registry entries
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
But be careful while using service check because some people might have different service names for MySQL service.
As in my case I have 2 installations of MySQL hence 2 services are present MySQL,MySQL501.
Hence it will be bit tedious to find out the correct service name.


Mind you HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB can remain in registry even on uninstall of MySQL. What gets removed is HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQL Server 5.1 but since we do not know the MySQL Server 5.1 part in advance, its not easy to go for this approach. Moreover MySQL need not be installed as such.

What is possible is to check HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MySQL\ImagePath and then see if the path specified by the value exists. The second part is important because MySQL need not remove the service key during uninstallation if service is already turned off. So this registry value can remain even after uninstallation. So the best option is to get the path of the executable from the above mentioned registry and then see if the mysqld.exe or (whatever it is) exists. MySQL is not installed if either the registry value doesn't exist or if the file doesnt exist. The catch here is that this logic fails if MySQL is installed but not configured to start its service (which means there is no key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MySQL). But thats trivial, since running MySQL installations will anyway have it and most machines will have MySQL running. Now even if the installed MySQL is not configured to have a service, its quite okay to install another version of your MySQL and register your service first.

I'm unsure of a perfect solution, the reason being MySQL being not a proprietary software. I mean anyone can bundle MySQL and install in their own flavours. For example, wampserver comes with their own MySQL. Client machines most certainly wont have servers installed that way, but we can not rule out the option and we may not want another MySQL instance (Note that a separate instance of MySQL runs fine along with MySQL in wamp server). What I do is check the above, if I did not find, I check for the image path of wamp service, like HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\wampmysqld\ImagePath. It depends on the server you have on a machine.