How to make silent mysql installation in inno setup?

I would create an installer for my java application. It uses the mysql database, so installing my program should include installing the mysql 5.5 server, setting up the server, and loading my database. I use Inno for this, but I found some problems. I found this code, but it's a little old

Filename: msiexec; Parameters: "/i mysql-5.5.11-win32.msi /qn INSTALLDIR=""C:\mysql"""; WorkingDir: C:\Users\Gabriele\Desktop\setup; StatusMsg: Sto installando Mysql 5.5.11; Flags: runhidden Filename: C:\mysql\bin\mysqld-nt.exe; Parameters: --install; WorkingDir: C:\mysql\bin; StatusMsg: Sto installando il Servizio MySQL; Description: Installing MySQL Service; Flags: runhidden Filename: net.exe; Parameters: start mysql; StatusMsg: Sto Avviando il Servizio MySQL; Description: Avvio Servizio MySQL; Flags: runhidden Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""insert into mysql.user(host,user,password) values ('localhost','root', PASSWORD('emmaus');"" -u root"; WorkingDir: {tmp}; StatusMsg: Configurazione del Server della Base di Dati; Flags: runhidden Filename: C:\mysql\bin\mysql.exe; Parameters: "-u root -h localhost -e ""create database ata"; Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""grant all privileges on ata.* to ata;"" -u root"; WorkingDir: {tmp}; StatusMsg: Configurazione Server Base di Dati; Flags: runhidden Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""flush privileges;"" -u root"; WorkingDir: {tmp}; StatusMsg: Configurazione Server Base di Dati; Flags: runhidden Filename: C:\mysql\bin\mysql.exe; Parameters: "-u root -h localhost -e ""use ata; source ata.sql;"; WorkingDir: {tmp}; StatusMsg: Caricamento base di dati; Flags: runhidden 

when I debug it, an error is generated after the first statement. cannot find the specified program in the second instruction. I tried using mysqld instead of mysqld-nt but nothing changed

Can someone help me?

+4
source share
2 answers
 [Files] Source: "J:\mysql-5.5.11-win32.msi"; DestDir: "{tmp}"; Flags: nocompression dontcopy [Run] Filename: "{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.5,Location}\bin\mysqld.exe"; Parameters: "--install"; WorkingDir: "{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.5,Location}\bin"; StatusMsg: "Sto installando il Servizio MySQL"; Description: "Installing MySQL Service"; Flags: runhidden; Check: MySQL_Is ;//and the rest of commands [Code] function MySQL_Is(): Boolean; var iResultCode: Integer; begin Result := true; if (not RegKeyExists(HKLM, 'SOFTWARE\MySQL AB\MySQL Server 5.5')) or (not FileExists(ExpandConstant('{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.5,Location}\bin\mysql.exe'))) then begin ExtractTemporaryFile('mysql-5.5.11-win32.msi'); Exec('msiexec.exe', '/i mysql-5.5.11-win32.msi /qn INSTALLDIR="C:\mysql"', ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, iResultCode); if not FileExists(ExpandConstant('{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.5,Location}\bin\mysql.exe')) then begin MsgBox('Something went wrong! Installation should be terminated', mbInformation, MB_OK); Result := false; end; end; end; 
+8
source

I leave my version of mysql installation here using inno setup, in which you can configure the port and service name for version 5.6 using customPage. I have not tried it with other versions. This solution was found thanks to other contributions.

 [Registry] Root: HKLM; Subkey: "SOFTWARE\MySoftware\G2Database"; ValueType: string; ValueName: Port; ValueData: {code:GetPort}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue Root: HKLM; Subkey: "SOFTWARE\MySoftware\G2Database"; ValueType: string; ValueName: ServiceName; ValueData: {code:GetServiceName}; Flags: createvalueifdoesntexist uninsdeletekeyifempty uninsdeletevalue We create 2 registers to save the data of Port and service name 
 [FILES] Source: "{#InstallersDir}MysqlServer\server_5631_win32.msi"; DestDir: "{tmp}"; Flags: ignoreversion nocompression; Tasks: Mysql Source: "{#InstallersDir}MysqlServer\script.txt"; DestDir: "{app}\mysql\bin"; Flags: ignoreversion nocompression ; Tasks: Mysql Source: "{#InstallersDir}MysqlServer\users.bat"; DestDir: "{app}\mysql\bin"; Flags: ignoreversion nocompression ; Tasks: Mysql [CODE] var lblPort: TLabel; lblServiceName: TLabel; ePort: TEdit; eServiceName: TEdit; procedure frmDBSettingsReg_Activate(Page: TWizardPage); begin end; function frmDBSettingsReg_ShouldSkipPage(Page: TWizardPage): Boolean; begin Result := False; end; function frmDBSettingsReg_BackButtonClick(Page: TWizardPage): Boolean; begin Result := True; end; function frmDBSettingsReg_NextButtonClick(Page: TWizardPage): Boolean; begin Result := True; end; procedure frmDBSettingsReg_CancelButtonClick(Page: TWizardPage; var Cancel, Confirm: Boolean); begin end; function frmDBSettingsReg_CreatePage(PreviousPageId: Integer): Integer; var Page: TWizardPage; begin Page := CreateCustomPage( PreviousPageId, ExpandConstant('{cm:AdvancedSettings}'), ExpandConstant('{cm:AdvancedDescription}') ); { lblPort } lblPort := TLabel.Create(Page); with lblPort do begin Parent := Page.Surface; Left := ScaleX(24); Top := ScaleY(30); Width := ScaleX(35); Height := ScaleY(13); Caption := ExpandConstant('{cm:Port}'); end; { lblServiceName } lblServiceName := TLabel.Create(Page); with lblServiceName do begin Parent := Page.Surface; Left := ScaleX(24); Top := ScaleY(60); Width := ScaleX(52); Height := ScaleY(13); Caption := ExpandConstant('{cm:ServiceName}') ; end; { ePort } ePort := TEdit.Create(Page); with ePort do begin Parent := Page.Surface; Left := ScaleX(130); Top := ScaleY(27); Width := ScaleX(185); Height := ScaleY(21); Text := '3306'; TabOrder := 0; end; { eServiceName } eServiceName := TEdit.Create(Page); with eServiceName do begin Parent := Page.Surface; Left := ScaleX(130); Top := ScaleY(56); Width := ScaleX(185); Height := ScaleY(21); Text := 'G2Database'; TabOrder := 1; end; with Page do begin OnActivate := @frmDBSettingsReg_Activate; OnShouldSkipPage := @frmDBSettingsReg_ShouldSkipPage; OnBackButtonClick := @frmDBSettingsReg_BackButtonClick; OnNextButtonClick := @frmDBSettingsReg_NextButtonClick; OnCancelButtonClick := @frmDBSettingsReg_CancelButtonClick; end; Result := Page.ID; end; function GetPort(param: String): String; begin Result := Trim(ePort.Text); end; function GetServiceName(param: String): String; begin Result := Trim(eServiceName.Text); end; ''' We create a new CustomPage to let user set Port and Servicename {cm:X} means CustomMessage just has to put your own text and remove ExpandConstant In my case I wanted to skip the MySQL configuration in case you don't mark the task ''' function ShouldSkipPage(curPageId:Integer):Boolean; begin if curPageID <> 100 then //Need to check if in your case is same ID Result := false else if ((curPageID = 100) and not WizardIsTaskSelected('Mysql')) then Result := true end; [RUN] ;Install MySQL Filename: msiexec.exe; Parameters:"/i""{tmp}\server_5631_win32.msi"" /qn INSTALLDIR=""YOUR RUTE"" DATADIR=""YOUR RUTE"" PORT=""{code:GetPort}"" "; WorkingDir:{app}; StatusMsg:"{cm:waitDatabase}"; Flags: runhidden; Tasks: Mysql ;Install Service Filename: YOUR RUTE\mysqld.exe; Parameters:"--install {code:GetServiceName} --port=""{code:GetPort}"""; WorkingDir:{app}; Flags: runhidden; Tasks: Mysql ;Start Service Filename: net.exe; Parameters: start {code:GetServiceName}; WorkingDir:{app}; StatusMsg:{cm:startDatabase}; Flags: runhidden; Tasks: Mysql ;Open Firewall Port Filename: netsh; Parameters: firewall add portopening TCP {code:GetPort} {code:GetServiceName}; Flags: runhidden; StatusMsg:{cm:configureDatabase}; Tasks: Mysql ;Create Custom users Filename: {app}\mysql\bin\users.bat; Parameters:" {code:MySQLPath} {code:FormatRute} {code:GetPort}"; StatusMsg:{cm:configureDatabase};Flags: runhidden;Tasks: Mysql ''' Here comes Script.txt and Users.bat and Aux Functions for them ''' Script.txt use mysql; update user set password=PASSWORD("root") where user='root'; CREATE USER 'myUser'@'%' IDENTIFIED BY 'myUser'; GRANT ALL PRIVILEGES ON * . * TO 'myUser'@'%'; CREATE USER 'myUser'@'localhost' IDENTIFIED BY 'myUser'; GRANT ALL PRIVILEGES ON * . * TO 'myUser'@'localhost'; FLUSH PRIVILEGES; Users.bat :: Move to mysql dir cd %1 :: Start session with user root -Port and execute script call "mysql.exe" -u root -P %3 < %2/script.txt //All this functions will go at CODE section function MySQLPath(Param:String):String; var Path: string; begin Path := ExpandConstant('{pf}\MySQL\MySQLServer5.6\bin'); Result := FileSearch ('mysqld.exe',Path ); StringChangeEx(Result, 'mysqld.exe', '', True); Result := '"' + Result + '"'; end; function FormatRute(Param:String):String; begin Result := ExpandConstant('{app}\mysql\bin'); Result := '"' + Result + '"' end; 
0
source

Source: https://habr.com/ru/post/1502406/


All Articles