Click here to Skip to main content
14,921,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to install and start MySQL service to run with my project.

1- I downloaded MySQL server 5.7.17 and configured it to as this tutorial : Manually Installing and Configuring MySQL 5.7 on Windows 10

2- i copied the MySQL Folder and put it inside my project folder (MyProject\bin\Debug\mysql)

3- using this code to install and start MySQL Service with custom name.
var serviceExists = ServiceController.GetServices().Any(s => s.ServiceName == "mysqlTests");
            if (!serviceExists)
            {
                ServiceProcessInstaller ProcesServiceInstaller = new ServiceProcessInstaller();
                ProcesServiceInstaller.Account = ServiceAccount.LocalSystem;
                ProcesServiceInstaller.Username = null;
                ProcesServiceInstaller.Password = null;

                ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
                InstallContext Context = new System.Configuration.Install.InstallContext();
                String path = String.Format("/assemblypath={0}", "mysql/bin/mysqld.exe");
                String[] cmdline = { path };

                Context = new InstallContext("", cmdline);
                ServiceInstallerObj.Context = Context;
                ServiceInstallerObj.DisplayName = "mysqlTests";
                ServiceInstallerObj.Description = "MySQL";
                ServiceInstallerObj.ServiceName = "mysqlTests";
                ServiceInstallerObj.StartType = ServiceStartMode.Automatic;
                ServiceInstallerObj.Parent = ProcesServiceInstaller;

                System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
                ServiceInstallerObj.Install(state);

            }

            ServiceController controller = new ServiceController();
            controller.ServiceName = "mysqlTests";
            if (controller.Status == ServiceControllerStatus.Stopped)
            {
                // Start the service
                controller.Start();
            }

i think the service installed successfully but this error appear : $exception {"Cannot start service mysqlTests on computer '.'."} System.InvalidOperationException Win32Exception: The system cannot find the file specified

as the attachment image: the service name seem to be installed


UPDATE:i update the code :
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
 String path = String.Format("/assemblypath={0}", appPath + @"\mysql\bin\mysqld");

the error :
System.InvalidOperationException: 'Cannot start service mysqlTests on computer '.'.'
Win32Exception: The service did not respond to the start or control request in a timely fashion

What I have tried:

I tried to install the service manually with the command :

mysqld --install mysqlTests

the Service successfully installed.

and successfully start

E:\MyProject\bin\Debug\mysql\bin>net start mysqlTests


I don't know what I can do to make my code install and start MySQL service successfully
Posted
Updated 21-Feb-18 1:18am
v3
Comments
j snooze 20-Feb-18 17:36pm
   
If you look at the administrative panel in the services and find the mysql service what is the path of the exe it is looking for? Is the exe there?
Golden Basim 20-Feb-18 18:25pm
   
i don't know where ( administrative panel) but in mysql service properties the path don't contain .exe
Dave Kreskowiak 20-Feb-18 20:06pm
   
Start -> Run -> Type services.msc and hit enter. Find the MySQL service and double-click it to get the Properties page on it. You'll find the path in there.
Golden Basim 21-Feb-18 5:38am
   
yes ..

"mysql\bin\mysqld.exe"
Dave Kreskowiak 21-Feb-18 8:36am
   
Well, unless your application is installed off the root of C:, this isn't going to work. The copy of MySQL isn't the "installed" copy and won't work as a service.

Seriously, why are you trying to install MySQL from your own application? Normal users don't have the permissions to install anything, so this isn't going to work.
Golden Basim 21-Feb-18 8:39am
   
I tried to install MySQL server with the advanced installer but I failed more times.
Dave Kreskowiak 21-Feb-18 8:47am
   
Do yourself a HUGE favor and just install MySQL separately from your own application installer.
Golden Basim 21-Feb-18 9:10am
   
what I need to make user install it with my application easy
Dave Kreskowiak 21-Feb-18 9:45am
   
I have no idea. I never use MySQL for anything.
Golden Basim 21-Feb-18 5:38am
   
"mysql\bin\mysqld.exe"
Golden Basim 21-Feb-18 5:49am
   
i update the code :
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
String path = String.Format("/assemblypath={0}", appPath + @"\mysql\bin\mysqld");

the error :
System.InvalidOperationException: 'Cannot start service mysqlTests on computer '.'.'
Win32Exception: The service did not respond to the start or control request in a timely fashion

1 solution

You are not following best practice. Your app's installer should run the MySQL installer. Your code can then start the service if it's not already running, but it seems to me that the service should indeed be running if you run the MySQL installer correctly.
   
Comments
Golden Basim 21-Feb-18 8:31am
   
i tried that with advanced installer
as this post
https://www.advancedinstaller.com/forums/viewtopic.php?f=2&t=21072&sid=f168367743c73f2972865634d11ef5bd

and itried another aproache :
https://www.advancedinstaller.com/forums/viewtopic.php?f=2&t=35086

but the same error appear

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900