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:





11 comments:

  1. Thank u. Helped me a lot! I was trying to make a setup to my software and finally i have finished!

    ReplyDelete
    Replies
    1. Happy it helped, examples of Inno working with other apps are hard to come by - especially under different systems.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Replies
    1. Hi Rozky, that's just the script that creates the database. Runs all the create table commands and so on. I've written in the above article why I've had to use a separate sql deployment file.
      Regards

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Hello my script to add mysql is not working

      [Setup]
      AppName=Rootplanner
      AppVerName=Rootplanner
      DefaultGroupName=Rootplanner
      AppPublisher=L.G.O. Systems
      AppVersion=1.0
      AllowNoIcons=false
      AppCopyright=
      PrivilegesRequired=admin
      OutputBaseFilename=RootplannerSetup
      DefaultDirName={pf}\Rootplanner

      [Languages]
      Name: "french"; MessagesFile: "compiler:Languages\French.isl"

      [Tasks]
      Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:

      [Icons]
      Name: {group}\Rootplanner; Filename: {app}\Rootplanner.exe; WorkingDir: {app}; IconIndex: 0
      Name: {group}\Uninstall Rootplanner; Filename: {uninstallexe}
      Name: {userdesktop}\Rootplanner; Filename: {app}\Rootplanner.exe; Tasks: desktopicon; WorkingDir: {app}; IconIndex: 0

      [Files]
      Source: "mysql-installer-community-5.7.11.0.msi"; DestDir: "{tmp}";
      Source: "C:\files\Rootplanner.sql"; DestDir: "{tmp}";
      Source: "C:\files\loadDB.bat"; DestDir: "{tmp}";
      Source: "C:\files\dotnetfx_2.0.exe"; DestDir: "{tmp}";
      Source: "C:\files* "; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

      [Run]
      Filename: "{tmp}\dotnetfx_2.0.exe";
      Parameters: "/q"; WorkingDir:{tmp};
      Flags: runhidden;
      StatusMsg: Installation du Framework Net Microsoft 2.0

      Filename: msiexec.exe; Parameters: " /i""{tmp}\mysql-installer-community-5.7.11.0.msi"" /qn";
      StatusMsg: Unpacking Mysql 5.6.16.0 installation;
      Flags: runhidden

      Filename: "C:\Program Files (x86)\MySQL\MySQL Installer for Windows\MySQLInstallerConsole.exe";
      Parameters: "--action=install -t=Custom --config=mysql-server-5.0-win64:passwd=root --product=mysql-server-5.0-win64 --catalog=mysql-5.0-win64 --nowait";
      StatusMsg: Installing MySQL Server;
      Flags: runhidden

      Filename: "C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysqld.exe"; Parameters:" --install";
      WorkingDir: {app};
      StatusMsg: Installing MySQL Service;
      Flags: runhidden

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

      Filename: "{tmp}\loadDB.bat";
      StatusMsg: Loading database;
      Flags: runhidden



      Delete
    5. Hi,
      Have you tried running it without the "runhidden" flag? It should display some information about the potential errors in the console.

      Delete
  4. thank you very much for the article!

    ReplyDelete