Previous Section  < Day Day Up >  Next Section

11.1 Running MySQL on Windows

This section describes MySQL installation, startup, and shutdown procedures for Windows systems.

11.1.1 Installing the MySQL Distribution

MySQL distributions for Windows come in the form of Zip files and can be installed as follows:

  • Download and unpack the distribution that you want to install.

  • The folder created by unpacking the distribution contains a Setup.exe or .msi installer program that runs the Setup Wizard. The program that unpacks the distribution might invoke this program automatically. If not, run it yourself to install MySQL.

  • The default installation location is C:\mysql; this is the MySQL base directory. You can select another base directory, but if you do, you must specify this directory when you run the server. See section 11.3, "Runtime MySQL Configuration."

The Windows installer automatically sets up the data directory under the MySQL base installation directory. The default data directory is C:\mysql\data. Under this directory, the installer also creates a mysql directory for the mysql database that contains the initial MySQL accounts. Note that these accounts at this point have no passwords. Chapter 12, "Security Issues," discusses how to set up passwords.

11.1.2 Starting and Stopping the MySQL Server

Windows MySQL distributions include several servers. You should choose the one you want to use:

  • mysqld is the standard server. It includes both the MyISAM and InnoDB storage engines.

  • mysqld-nt is like mysqld, but includes support for Windows NT-named pipes. It is intended for NT-based systems such as Windows NT, 2000, and XP.

  • mysqld-max and mysql-max-nt are like mysqld and mysql-nt, but with additional features such as support for the BDB storage engine and for symlinking database directories.

The examples in the following discussion use mysqld for the server name; make the appropriate substitutions to use a different server. Note that even if you use a server that supports named pipes, it will not allow named pipe connections by default. To allow that type of connection, you must start the server with the --enable-named-pipe option.

See section 11.3, "Runtime MySQL Configuration," for instructions on specifying any server startup options you need.

11.1.2.1 Running the Server Manually

To run a Windows MySQL server manually, invoke it from the command line of a console window:






shell> mysqld


By default, Windows servers write error messages to the file host_name.err in the data directory, where host_name is the MySQL server hostname. (If you have an older version of MySQL 4, the error log might be named mysql.err instead.) If the server does not start properly, check the error log to see why. Alternatively, to display diagnostic output in the console window instead, invoke the server with the --console option:






shell> mysqld --console


Other server options may be specified on the command line or in option files. See section 11.3, "Runtime MySQL Configuration."

Note that when you invoke the server at the command prompt, the command interpreter might not display another prompt until the server exits. To invoke other MySQL programs while the server is running, open a new console window.

To stop the server, use mysqladmin from the command line:






shell> mysqladmin shutdown


Another way to stop the server is to use the MySQLCC program. It's also possible to use the Windows Task Manage2, although you should avoid that if you can because the Task Manager terminates the server forcibly without giving it a chance to perform a clean shutdown. The result might be data corruption or loss.

11.1.2.2 Running the Server as a Windows Service

On Windows NT–based systems, you can run the server manually, as just described, or you can install it as a Windows service. To use the service approach, invoke the server with the --install option:






shell> mysqld --install


This command does not actually start the server; it tells Windows to handle the server as a service. When Windows starts up or shuts down, it starts or stops mysqld automatically. The service also can be started or stopped manually from the command line. To do so, use these commands:






shell> net start MySQL



shell> net stop MySQL


MySQL is the service name for MySQL. It can be given in any lettercase.

You can also shut down the server manually using mysqladmin shutdown or with MySQLCC.

To control the service using a graphical interface, use the Windows Services Manager. It displays a window that lists all known services and has controls for starting and stopping them.

If the server does not start properly when run as a service, check the error log or run the server manually with the --console option as described in section 11.1.2.1, "Running the Server Manually."

If you want to specify runtime options for a MySQL server that is to run as a service, don't give them on the --install command line. Instead, put the options in an option file. The server normally reads options from the [mysqld] group of the standard Windows option files when it starts up. (These files are described in section 11.3, "Runtime MySQL Configuration.") To use a specific option file, use a command like this to install the service:






shell> mysqld --install MySQL --defaults-file=file_name


In this case, when the server starts, it reads options in the [mysqld] option group of the named file, and ignores the standard option files.

To remove the MySQL service, shut down the server if it's running (using any of the means just described), and then issue the following command:






shell> mysqld --remove


    Previous Section  < Day Day Up >  Next Section