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)
{
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