Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

delphi

I'm developing an installer for my program for Windows OS.

I'd like the installer to check if MySQL is already installed and if it isn't silently install MySQL before installation is over.

How can I check if MySQL is already on the computer with delphi?

like image 610
SimonM Avatar asked Feb 21 '12 15:02

SimonM


Video Answer


2 Answers

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.
like image 140
da-soft Avatar answered Oct 22 '22 22:10

da-soft


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.

like image 31
Shirish11 Avatar answered Oct 22 '22 22:10

Shirish11