11

我已经阅读了很多关于 Stack Overflow 的文档,你们太棒了!我采用了另一篇文章中建议的一些代码。帮助很棒!感谢 RobeN,我能够加载并启动 MySQL。但是,我确实阅读了建议将数据库自动加载到序列中的文档。我似乎无法弄清楚。任何帮助都会很棒!

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Test"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "DispatchSystem.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{790A9827-137F-4D93-A981-1A5C38FFB8F8}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=C:\gd\FL\Project\xsbucks_vc\inno\
OutputBaseFilename=Logistics Dispatch
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:\SWW\CaLogistics\EXE\mysql-5.5.11-win32.msi"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\DispatchSystem.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\background.fw.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\background.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\background234.jpg"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\database.sql"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\ds.ini"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\Ionic.Zip.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\logo.jpg"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\logo.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\MySql.Data.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\SWW\CaLogistics\EXE\MySqlBackup.dll"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: msiexec; Parameters: "/i mysql-5.5.11-win32.msi /qn INSTALLDIR=""C:\mysql"""; WorkingDir:{app}; StatusMsg: Please wait while we install Mysql 5.5.11;  Flags: runhidden

Filename: C:\mysql\bin\mysqld.exe; Parameters:" --install"; WorkingDir: {app}; StatusMsg: Installing MySQL services; Description: Installing MySQL Service; Flags: runhidden

Filename: net.exe; Parameters: start mysql; StatusMsg: Starting MySQL server; Description: Starting MySQL Server; Flags: runhidden

Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""update mysql.user set password=PASSWORD('admin') where user='root';"" -u root"; WorkingDir: {app}; StatusMsg: Configuring MYSQL ; Flags: runhidden

Filename: C:\mysql\bin\mysql.exe; Parameters: "-e ""flush privileges;"" -u root -padmin"; WorkingDir: {app}; StatusMsg: Configuring Database Servers; Flags: runhidden

Filename: C:\mysql\bin\mysql.exe; Parameters: "-u root -padmin -h localhost --execute=""SOURCE database.sql"""; WorkingDir: {app}; StatusMsg: Loading Database; Flags: runhidden
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[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;
4

2 回答 2

8

我设法找到了解决此问题的方法。我没有直接从 INNO 脚本加载数据库,而是将 sql 命令写入批处理文件并从脚本执行 .bat。

将其键入记事本文档并将其保存为 loadDB.bat 。第一行将目录的路径设置为安装 mysql.exe 的位置。下一行创建一个空数据库。(我不知道为什么,但是如果不先在服务器上创建一个空数据库,我就无法让 mysql 加载数据库文件)最后一行是用于从数据库加载数据库的 mysql 命令,sql 文件。

cd /d C:\Program Files\MySQL\MySQL Server 5.1\bin

mysql -uroot -padmin -e "创建数据库 mydatabase;"

mysql -uroot -padmin mydatabase < "C:\database.sql"

现在,在 [FILES] 部分下方的 INNO 脚本中添加 .bat 文件

来源:“文件路径\loadDB.bat”;目标目录:“{app}”;标志:忽略版本

在 [RUN] 部分下方执行 .bat。注意这一行应该是 [RUN] 部分的最后一行,因为它应该只在安装 Mysql 服务器后执行。

文件名:“{app}\loadDB.bat”

现在编译并运行设置。

作为旁注:我还没有尝试过,但是如果您将 .bat 中的 mysql 命令直接添加到具有正确参数的 inno 脚本中,您可以在不需要批处理文件的情况下加载数据库。

希望这能解决您的问题。

于 2013-11-15T14:14:17.660 回答
6

安装 MySQL 并启动后,很容易加载 MySQL 脚本文件。

关键点是将命令“ source ”传递给mysql.exe -e 参数,因此它可以加载脚本文件。使用“<”信号传递脚本名称对我不起作用。

[Files]
Source: "script.sql"; DestDir: "{tmp}"; Flags: deleteafterinstall;

[Run]
Filename: "{reg:HKLM\SOFTWARE\MySQL AB\MySQL Server 5.6,Location}\bin\mysql.exe"; \
 Parameters: "-u root -prootpassword -e ""source {tmp}\script.sql"""; \
 StatusMsg: "Loading MySQL Database Initial Data"; \
 Flags: runhidden waituntilterminated;
于 2015-02-18T15:27:31.213 回答