我会为我的java应用程序创建一个安装程序。它使用mysql数据库,所以我的程序的安装必须包括安装mysql server 5.5,配置服务器和加载我的数据库。我使用Inno设置这样做但我发现了一些问题。我找到了这段代码,但它有点旧了
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
当我调试它在第一个语句后生成错误。在第二条指令中找不到指定的程序。我尝试使用mysqld而不是mysqld-nt,但没有任何改变
有人能帮帮我吗?
答案 0 :(得分:8)
[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;
答案 1 :(得分:0)
我在这里使用inno setup离开我的mysql安装版本,在其中您可以使用customPage自定义5.6版的端口和服务名称,而其他版本则没有尝试过。找到了这种解决方案,这要归功于其他贡献
[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;