2.3.5.13 MySQL Server Instance Config Wizard: Creating an Instance from the Command Line

In addition to using the GUI interface to the MySQL Server Instance Config Wizard, you can also create instances automatically from the command line.

To use the MySQL Server Instance Config Wizard on the command line, you need to use the MySQLInstanceConfig.exe command that is installed with MySQL in the bin directory within the installation directory. MySQLInstanceConfig.exe takes a number of command-line arguments the set the properties that would normally be selected through the GUI interface, and then creates a new configuration file (my.ini) by combining these selections with a template configuration file to produce the working configuration file.

The main command line options are provided in the table below. Some of the options are required, while some options are optional.

Table 2.7 MySQL Server Instance Config Wizard Command Line Options

OptionDescription
Required Parameters
-nPRODUCTNAMEThe name of the instance when installed
-pPATHPath of the base directory for installation. This is equivalent to the directory when using the basedir configuration parameter
-vVERSIONThe version tag to use for this installation
Action to Perform
-iInstall an instance
-rRemove an instance
-sStop an existing instance
-qPerform the operation quietly
-lFILENAMESae the installation progress in a logfile
Config File to Use
-tFILENAMEPath to the template config file that will be used to generate the installed configuration file
-cFILENAMEPath to a config file to be generated

The -t and -c options work together to set the configuration parameters for a new instance. The -t option specifies the template configuration file to use as the basic configuration, which are then merged with the configuration parameters generated by the MySQL Server Instance Config Wizard into the configuration file specified by the -c option.

A sample template file, my-template.ini is provided in the toplevel MySQL installation directory. The file contains elements are replaced automatically by the MySQL Server Instance Config Wizard during configuration.

If you specify a configuration file that already exists, the existing configuration file will be saved in the file with the original, with the date and time added. For example, the mysql.ini will be copied to mysql 2009-10-27 1646.ini.bak.

The parameters that you can specify on the command line are listed in the table below.

Table 2.8 MySQL Server Instance Config Wizard Parameters

ParameterDescription
ServiceName=$Specify the name of the service to be created
AddBinToPath={yes | no}Specifies whether to add the binary directory of MySQL to the standard PATH environment variable
ServerType={DEVELOPMENT | SERVER | DEDICATED}Specify the server type. For more information, see Section 2.3.5.4, “MySQL Server Instance Config Wizard: The Server Type Dialog”
DatabaseType={MIXED | INNODB | MYISAM}Specify the default database type. For more information, see Section 2.3.5.5, “MySQL Server Instance Config Wizard: The Database Usage Dialog”
ConnectionUsage={DSS | OLTP}Specify the type of connection support, this automates the setting for the number of concurrent connections (see the ConnectionCount parameter). For more information, see Section 2.3.5.7, “MySQL Server Instance Config Wizard: The Concurrent Connections Dialog”
ConnectionCount=#Specify the number of concurrent connections to support. For more information, see Section 2.3.5.4, “MySQL Server Instance Config Wizard: The Server Type Dialog”
SkipNetworking={yes | no}Specify whether network support should be supported. Specifying yes disables network access altogether
Port=#Specify the network port number to use for network connections. For more information, see Section 2.3.5.8, “MySQL Server Instance Config Wizard: The Networking and Strict Mode Options Dialog”
StrictMode={yes | no}Specify whether to use the strict SQL mode. For more information, see Section 2.3.5.8, “MySQL Server Instance Config Wizard: The Networking and Strict Mode Options Dialog”
Charset=$Specify the default character set. For more information, see Section 2.3.5.9, “MySQL Server Instance Config Wizard: The Character Set Dialog”
RootPassword=$Specify the root password
RootCurrentPassword=$Specify the current root password then stopping or reconfiguring an existing service

Note

When specifying options on the command line, you can enclose the entire command-line option and the value you are specifying using double quotation marks. This enables you to use spaces in the options. For example, "-cC:\mysql.ini".

The following command installs a MySQL Server 5.1 instance from the directory C:\Program Files\MySQL\MySQL Server 5.1 using the service name MySQL51 and setting the root password to 1234.

shell> MySQLInstanceConfig.exe -i -q "-lC:\mysql_install_log.txt" »
   "-nMySQL Server 5.1" "-pC:\Program Files\MySQL\MySQL Server 5.1" -v5.1.73 »
   "-tmy-template.ini" "-cC:\mytest.ini" ServerType=DEVELOPMENT DatabaseType=MIXED »
   ConnectionUsage=DSS Port=3311 ServiceName=MySQL51 RootPassword=1234

In the above example, a log file will be generated in mysql_install_log.txt containing the information about the instance creation process. The log file generated by the above example is shown below:

Welcome to the MySQL Server Instance Configuration Wizard 1.0.16.0
Date: 2009-10-27 17:07:21

Installing service ...

Product Name:         MySQL Server 5.1
Version:              5.1.73
Installation Path:    C:\Program Files\MySQL\MySQL Server 5.1\

Creating configuration file C:\mytest.ini using template my-template.ini.
Options:
DEVELOPMENT
MIXED
DSS
STRICTMODE

Variables:
port: 3311
default-character-set: latin1
basedir: "C:/Program Files/MySQL/MySQL Server 5.1/"
datadir: "C:/Program Files/MySQL/MySQL Server 5.1/Data/"


Creating Windows service entry.
Service name: "MySQL51"
Parameters:   "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld" --defaults-file="C:\mytest.ini" MySQL51.
Windows service MySQL51 installed.

When using the command line, the return values in the following table indicate an error performing the specified option.

Table 2.9 Return Value from MySQL Server Instance Config Wizard

ValueDescription
2Configuration template file cannot be found
3The Windows service entry cannot be created
4Could not connect to the Service Control Manager
5The MySQL service cannot be started
6The MySQL service cannot be stopped
7The security settings cannot be applied
8The configuration file cannot be written
9The Windows service entry cannot be removed

You can perform an installation of MySQL automatically using the MSI package. For more information, see Section 2.3.4.2, “Automating MySQL Installation on Microsoft Windows Using the MSI Package”.