Mysql – Installing isolated instance of MySQL on Windows using silent install with .msi

MySQL

I'm trying to write an installer for an internal application we wrote. After it installs our application it then installs MySQL using the .msi installer in silent mode. I specify the install dir and data dir to that of a directory within my application's install directory, such as:

msiexec /i @@MYSQL_INSTALLER_FILE@@ /qn 
    INSTALLDIR="@@INSTALL_DIR@@\MySQL\" 
    DATADIR="@@INSTALL_DIR@@\MySQL\" 
    USERNAME="@@DB_USER@@" PASSWORD="@@DB_PASS@@"

(the @@variable@@'s are replace by my installer routine using InstallJammer)

Once installed, I use mysqld.exe to install a windows service with a custom service name and defaults file like so:

mysqld.exe --install CustomMySQL --defaults-file="@@INSTALL_DIR@@\MySQL\my.ini"

This works fine as long as there is not already another instance of MySQL installed. If there is it silently fails to install MySQL. Running the msi installer manually (double-click) shows an error that a previous version is already installed and just aborts.

Is there a way to automate installing MySQL as an isolated instance, regardless of whether another version/instance is already installed?

Best Answer

Oh yes there is.

For one thing, I am not a big fan of using .msi for MySQL.

I like doing the following to create a full Windows service without using .msi

01) Download the no-install zip of MySQL to your desktop.

02) Open the Zip File in Window1. You should see the data folder, bin folder, several my.ini files and other files.

03) Create a Server Folder and a Data Folder in a Desired Location. For this example, in a DOS Window, do the following :

md C:\MySQLServer
md C:\MySQLData

04) Open C:\MySQLServer in Window Explorer (Window2)

05) Copy and Paste the Zip Contents (Window1) into the C:\MySQLServer (Window2)

06) Open C:\MySQLServer\data in Windows Explorer (Window3)

07) Open C:\MySQLData in Window Explorer (Window4)

08) Copy and Paste the Contents of C:\MySQLServer\data (Window3) into C:\MySQLData (Window4)

09) Close Window3 and Window4

10) Open a DOS Window and run the following DOS commands

cd C:\MySQLServer
copy my-medium.ini my.ini
notepad my.ini
define datadir="C:\\MySQLData"
cd C:\MySQLServer\bin
mysqld --install MySQLNew
net start MySQLNew

11) Close all Windows

You should be done !!!

Let us know how it turned out !!!

BTW The service name turns out as MySQLNew

Related Topic