Installing MySQL on Windows

You can run MySQL on NT-based systems, such as Windows NT, 2000, and XP, or on non-NT systems, such as Windows 95, 98, and Me. To do so, you must have TCP/IP support installed. On Windows NT 4, make sure your system is at service pack 3 or later. On Windows 95, make sure your Winsock software is at least version 2.

I recommend that you use an NT-based version of Windows if possible. Then you'll have the option of running the MySQL server as a service that Windows starts and stops automatically at system startup and shutdown time. The NT servers also support the option of allowing clients to connect over named pipes.

In addition to the MySQL server and client programs, you may also want to install MyODBC, the MySQL driver for the ODBC (Open Database Connectivity) standard developed by Microsoft. MyODBC allows ODBC-compliant programs to access MySQL databases. For example, you can install MyODBC and then use ODBC programs such as Microsoft Access to connect to a MySQL server.

Windows MySQL distributions are available from the MySQL Web site as ZIP files, with filenames in the form To unpack a ZIP file, just double-click it. If that does not work, use a program such as WinZip, pkunzip, or unzip. The result will be a folder that contains a Setup.exe application that you should launch to install MySQL. The default installation location is C:\mysql, but you can select a different directory.

After installing MySQL on Windows, it is unnecessary to initialize the data directory or the grant tables because they are included pre-initialized in the distribution. However, if you install MySQL in any location other than the default of C:\mysql, you must place a [mysqld] option group in an option file that the server reads when it starts up so that it can determine where the installation base directory and the data directory are located. (The option file can be either C:\my.cnf or the my.ini file in your Windows system directory.) For example, if you install MySQL in E:\mysql, the option group should look like the following (note the use of forward slashes in the pathnames rather than backslashes):


You'll also need to change the pathnames in the commands shown in the following instructions if you select an installation directory other than the default.

On Windows, you can choose from the following servers:

Server Description
mysqld Standard server
mysqld-nt Optimized server with named pipe support
mysqld-max Optimized server with transaction and symbolic link support
mysqld-max-nt Like mysqld-max but with named pipe support

The servers with -nt in their name support connections over named pipes when run on NT-based systems. However, named pipe support is enabled by default only prior to MySQL 3.23.50. To use this capability from 3.23.50 on, you should add a line to the [mysqld] group in your option file:


On Windows NT-based systems, the mysqld-nt server can be installed to run as a service that starts automatically whenever Windows starts (you can substitute mysqld-max-nt in the following command):

C:\> C:\mysql\bin\mysqld-nt --install 

If you use --install-manual rather than --install, the server is installed as a manual service that does not run automatically when Windows starts up.

If you install mysqld-nt as a service, you can specify other options by putting them in the [mysqld] group of an option file.

For a server that is installed as a service, you can start it manually using the Windows Services Manager. You should be able to find this as a Services item in the Windows Control Panel or in the Administrative Tools item in the Control Panel. The service also can be started using the following command:

C:\> net start MySQL 

To stop the server, use the Services Manager or one of the following commands:

C:\> net stop MySQL 
C:\> C:\mysql\bin\mysqladmin -u root shutdown

To remove MySQL as a service, shut down the server if it is running, and then invoke the following command:

C:\> C:\mysql\bin\mysqld-nt --remove 

To avoid interactions between the Services Manager and commands issued from the DOS prompt, it is best to close the Services Manager whenever you invoke service-related commands from the prompt.

On non-NT-based systems (or on NT systems if you do not install the server as a service), you must start and stop the server manually from the command line. To run mysqld, start it as follows (you can substitute mysqld-max in this command):

C:\> C:\mysql\bin\mysqld 

You can specify other options on the command line if you want. To shut down the server, use mysqladmin:

C:\> C:\mysql\bin\mysqladmin -u root shutdown 

To run a server in console mode (so that it displays error messages in a console window), invoke it as follows:

C:\> C:\mysql\bin\mysqld --console 

Any of the servers can be run in console mode. In this case, you can specify other options on the command line after the --console option or in an option file. To shut down the server, use mysqladmin.

If you have problems getting the server to run, check the Windows notes in the installation chapter in the MySQL Reference Manual.

To allow invocation of MySQL client programs from the command line without typing their full pathnames, set your PATH environment variable to include the C:\mysql\bin directory. (If you installed MySQL somewhere else, adjust the pathname appropriately.) You can set your path in the AUTOEXEC.BAT file or (on NT-based systems) by using the System item in the Control Panel.

The default installation allows anyone to connect to MySQL as root without a password, so you should set up passwords as described in Chapter 11, "General MySQL Administration." That chapter also contains instructions for other actions such as enabling logging or configuring the InnoDB table handler.

Installing Perl DBI Support on Windows

The easiest way to install Perl modules under Windows is to get the ActiveState Perl distribution from and install it. Then fetch and install the additional Perl modules that you need. The ppm (Perl Package Manager) program is used for this. To find out what modules are already installed, use this command:

C:\> ppm info 

Then install the modules you need using the appropriate commands from the following list. It's likely that will already be installed, but you'll probably need to install the DBI-related packages:

C:\> ppm 
ppm> install DBI
ppm> install DBD::mysql
ppm> install CGI

Installing Apache and PHP on Windows

Apache and PHP are available as Windows binaries from the Apache and PHP Web sites listed near the beginning of this appendix. Under Apache 1.3.x, PHP can be run only as a standalone CGI program. Under Apache 2.x, you can run PHP either as a standalone program or as an Apache module.

Installing MyODBC on Windows

Distributions of MyODBC 3 are packaged as executable files with filenames of the form MyODBC-version.exe. Download a distribution file and then launch it to install it. For versions prior to MyODBC 3, distributions are packaged as ZIP files. There are separate distributions for NT- and non-NT?based systems (distinguished by -nt and -win95 in the filenames). To install a ZIP-format distribution, double-click it to unpack it and then run the Setup.exe application inside the resulting folder. If you encounter an error such as "Problems while copying MFC30.DLL" while installing MyODBC with Setup.exe, MFC30.DLL is being used by some application. In this case, try selecting the Ignore option that is presented with the error message. MySQL should finish installing and most likely will work despite the error. If it doesn't, try restarting Windows in safe mode and running Setup.exe again.

After installing a MyODBC distribution, configure the driver using the ODBC item in the Control Panel. (It should be located in the Control Panel or in the Administrative Tools item in the Control Panel, with a name like Data Sources (ODBC) or ODBC Data Sources.) When you run the ODBC item, you'll see a window that allows you to set up a data source name (DSN). Click the User DSN tab and then click the Add button to bring up a window that lists the available data source drivers. Select the MySQL driver from the list and click the Finish button. Another window will appear that allows you to enter connection parameters for the data source. Fill in parameters that are appropriate for the connection that you want to establish and then click OK. The following example shows how to fill in the fields to set up a data source for connecting to the local server to access the sampdb database with a username and password of sampadm and secret:

Field Name Field Value
Data Source Name: sampdb-dsn
Host Name (or IP): localhost
Database Name: sampdb
User: sampadm
Password: secret
Port: 3306

After configuring MyODBC, you should be able to use ODBC-aware programs to access MySQL databases. For example, one common use for MyODBC is to connect to a MySQL server from Microsoft Access. After ODBC has been set up, use the following steps to connect to the MySQL server from within Access:

  1. Start the Access program.

  2. Open your database or create a new database.

  3. From the File menu, select Get External Data and then select Link Tables.

  4. In the window that appears, click the Files of Type pop-up menu and select ODBC Databases.

  5. Select the DSN that you configured in the Control Panel ODBC item for connecting to MySQL.

  6. Select the MySQL tables you want to use.

After performing this procedure, the selected tables will be available through Access.