Tuesday 11 February 2014

Inno Setup, installing MySQL server and .net 4.0

    I needed to create a package which I could install on a machine with at least Windows XP SP3 on board. Because I only have free Visual Studio 2012 Express, the simplest option was to use something that works out of the box and is easy to use. That's how I found Inno Setup, a nice app for creating setup packages.

And because it was not that easy to use from the get go I'll do a short summary of what I did to make it run on my bare Windows XP running inside of a VirtualBox.

Most of the options are described well enough in the documentation and samples. Hence I'll focus on two sections that are being used in the setup script used by Inno Setup.

[Files]
Source: "C:\SetupFiles\mysql-installer-community-5.6.16.0.msi"; DestDir: "{tmp}";
Source: "C:\SetupFiles\database.sql"; DestDir: "{tmp}";
Source: "C:\SetupFiles\loadDB.bat"; DestDir: "{tmp}";
Source: "C:\SetupFiles\dotNetFx40_Full_x86_x64.exe"; DestDir: "{tmp}";

Now, every DestDir is set to {tmp}, because the temp directory is being removed after the installation, and we won't need these files later.

Next is the [Run] section that describes how the above are gonna be installed. I'll add break lines in the listing below for the clarity, but in Inno Setup everything has to be in one line.

[Run]   

; Installing .net in quiet, unattended mode. 
Filename: "{tmp}\dotNetFx40_Full_x86_x64.exe";
Parameters: "/q"; WorkingDir:{tmp};
Flags: runhidden;
StatusMsg: Installing .Net Framework

; Installing MySQL installation package, which by default goes to C:\Program Files\MySQL\
; /qn also makes msiexec go quiet and unattended.
Filename: msiexec.exe; Parameters: " /i""{tmp}\mysql-installer-community-5.6.16.0.msi"" /qn";
StatusMsg: Unpacking Mysql 5.6.16.0 installation;
Flags: runhidden

; Using the MySQLInstallerConsole.exe to install the MySQL server. We need to set the type of installation
; ( -t ) to Custom to make it install only the server ( and omit for example Workbench ). We need to set the
; initial root password ( below set to root ). Lack of --nowait makes the console wait for user input.
Filename: "C:\Program Files\MySQL\MySQL Installer\MySQLInstallerConsole.exe";
Parameters: " --action=install -t=Custom --config=mysql-server-5.6-win32:passwd=root --product=mysql-server-5.6-win32 --catalog=mysql-5.6-win32 --nowait";
StatusMsg: Installing MySQL Server;
Flags: runhidden
                       
; Quite self explanatory, we just add mysql service to services currently running on the pc
Filename: "C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe"; Parameters:" --install";
WorkingDir: {app};
StatusMsg: Installing MySQL Service;
Flags: runhidden

; Starting the service
Filename: net.exe;
Parameters: start mysql;
StatusMsg: Starting MySQL Server;
Flags: runhidden

; Loading the database inside of a batch file, for some reason InnoDb has problems running queries using       ; mysql
Filename: "{tmp}\LoadDB.bat";
StatusMsg: Loading database;
Flags: runhidden  

        In case you're reinstalling using the setup, it might get more tricky because you must either remove the C:\Documents And Settings\All Users\Application Data\MySQL (in case of Windows XP) directory or pass the existing password to the MySQLInstallerConsole.exe config parameter.

          --action=install -t=Custom --config=mysql-server-5.6-win32:passwd=root;existingpasswd=root
          --product=mysql-server-5.6-win32 --catalog=mysql-5.6-win32

Both are pretty bad, and there's a bit of fiddling required to make them work on all systems, and under different circumstances.

Links: