Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL install and load database on Inno Setup script

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;
like image 807
Ron Kerr Avatar asked Oct 10 '13 14:10

Ron Kerr


2 Answers

After you installed MySQL and got it started, it´s easy to load an MySQL Script file.

The keypoint is passing the command "source" to mysql.exe -e parameter, so it could load the script file. Passing script name with "<" signal didn´t work for me.

[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;
like image 109
Fernando Vieira Avatar answered Nov 08 '22 12:11

Fernando Vieira


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.

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

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

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

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

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

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.

Filename: "{app}\loadDB.bat"

Now compile and run the setup.

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.

like image 8
quicksilver Avatar answered Nov 08 '22 11:11

quicksilver