MySQL在Inno Setup脚本上安装和加载数据库 [英] MySQL install and load database on Inno Setup script

查看:188
本文介绍了MySQL在Inno Setup脚本上安装和加载数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been reading through a lot of documents on Stack Overflow, you guys are great! I have taken some code that was suggested on another post. The help was great! I was able to get the MySQL loaded and started thanks to RobeN. I did however read the documentation that was suggested to autoload a database into the sequence. I can't seem to get it figured out. Any help would be great!

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

推荐答案

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

I managed find a workaround to this problem. Instead of loading the database directly from the INNO script, I wrote the sql commands into a batch file and executed the .bat from the script.

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

Type this into a notepad document and save it as loadDB.bat . The first line sets the path of your directory to where your mysql.exe is installed. Next line creates an empty database.(I don't know why but I can't get mysql to load the database file without creating an empty database on the server first) The last line is the mysql command for loading the database from your database,sql file.

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

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

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

mysql -uroot -padmin -e "create database mydatabase;"

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

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

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

Now, in your INNO script below the [FILES] section add the .bat file

来源:文件路径\ loadDB.bat"; DestDir:"{app}";标志:ignoreversion

Source: "path-to-file\loadDB.bat"; DestDir: "{app}"; Flags: ignoreversion

在[RUN]部分下面,执行.bat.请注意,此行应该是[RUN]部分的最后一行,因为它应该仅在安装Mysql服务器之后执行.

And below the [RUN] section execute the .bat. Note this line should be the last line in the [RUN] section because it should execute only after Mysql server is installed.

文件名:"{app} \ loadDB.bat"

Filename: "{app}\loadDB.bat"

现在编译并运行安装程序.

Now compile and run the setup.

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

As a side note : I havent tried it but maybe if you add the mysql commands in the .bat directly into the inno script with the correct parameters, you could load the database without the need of the batch file.

希望这可以解决您的问题.

Hope this solves your problem.

这篇关于MySQL在Inno Setup脚本上安装和加载数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆