Automated MySQL Install On Windows
If you need to install MySQL databases on a number of machines with roughly the same configuration then it becomes extremely tedious to run the installer wizard on each machine. You can download the MySQL server as a msi package which allows you to install with the MSIEXEC DOS command in windows hands free. To install all the necessary files for MySQL to run you need to type this command at the console:
msiexec /qn /i mysql-essential-5.1.37-win32.msi INSTALLDIR=C:\MySQL
The ‘/qn’ switch makes this install quiet. In this example I chose ‘C:\MySQL’ as the install directory. Feel free to replace that path with whatever you choose.
Just because MySQL is installed and has all the appropriate files registered doesn’t mean that it’s useful. You will probably want it to run as a service, have it listen on a certain port, and have a root user already set up. This can be done with the MySQLInstanceConfig.exe program, although the arguments are a little more involved.
C:\MySQL\bin\MySQLInstanceConfig.exe -i -q
"-lC:\MySQL\mysql_install_log.txt"
"-pC:\MySQL\bin" "-tC:\MySQL\my-template.ini"
"-cC:\MySQL\my.ini" -v5.1.37
ServerType=DEVELOPMENT
DatabaseType=MIXED
ConnectionUsage=DSS
Port=3306
ServiceName=MySQL
RootPassword=root1234
SkipNetworking=no
AddBinToPath=yes
The entire string above must be run as one line. If you just copy and paste then the console will error out. Most of the arguments above are straight forward if you’ve ever configured a MySQL server before but just in case I’ve detailed the parameters below.
-n product name
-p path of installation (no \bin)
-v version
Actions:
-i (install instance)
-r (remove instance)
-s (stop instance)
-q (be quiet)
-lfilename (write log file)
When launched manually, these can also be submitted
-t<.cnf template filename>
-c<.cnf filename>
Use the following options to define the parameters for the configuration file generation.
ServiceName=$
AddBinToPath={yes | no}
ServerType={DEVELOPMENT | SERVER | DEDICATED}
DatabaseType={MIXED | INNODB | MYISAM}
ConnectionUsage={DSS | OLTP}
ConnectionCount=#
SkipNetworking={yes | no}
Port=#
StrictMode={yes | no}
Charset=$
RootPassword=$
RootCurrentPassword=$
So if you use the example above you will get a basic mysql installation. When I used these commands I put them in a batch file followed by this command:
mysql –user=user_name –password=your_password db_name < create_database_and_tables.sql The ‘create_database_and_tables.sql’ obviously has all the sql code to create the MySQL databases and tables that are needed. The batch file installed, configured, and structured my MySQL databases. I spent awhile yesterday looking for a post like this so hopefully this saves someone some time.