Installing MySQL on WindowsYou can run MySQL on NT-based systems such as Windows NT, 2000, XP, and 2003, 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 that your system is at service pack 3 or later. On Windows 95, make sure that 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-specific MySQL servers (mysqld-nt and mysqld-max-nt) also support the option of allowing clients to connect using a named pipe. In addition to the MySQL server and client programs, you might also want to install Connector/ODBC, the MySQL driver for the ODBC (Open Database Connectivity) standard developed by Microsoft. Connector/ODBC allows ODBC-compliant programs to access MySQL databases. For example, you can install Connector/ODBC and then use ODBC programs such as Microsoft Access to connect to a MySQL server. As of MySQL 4.1.5, there are three distribution types to choose from on Windows:
The Complete and Essentials package installers like to put MySQL under C:\Program Files\MySQL rather than at C:\mysql. They also create a Start Menu entry and a key in the Windows registry, which the Noinstall package does not. Note: The Configuration Wizard included with the Complete and Essentials packages can upgrade a previous installation of MySQL automatically, but this capability has certain limitations:
Due to these limitations, if you're upgrading an existing MySQL installation, it's best to make a backup of your databases before installing a new version. For additional information about installing MySQL on Windows, see the installation chapter in the MySQL Reference Manual. If you want to be able to invoke MySQL programs from the command line without typing their full pathnames, set your PATH environment variable to include the bin directory under the location where MySQL is installed. For example, if you install MySQL in C:\mysql, add C:\mysql\bin to your path. You can set your path in the AUTOEXEC.BAT file or (on NT-based systems) by using the System item in the Control Panel. You might need to restart Windows for the change to take effect. After installing MySQL on Windows, it is not necessary 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 place other than the default location selected by the installer, you must place a [mysqld] option group in an option file that the server reads when it starts, so that it can determine where the installation base directory and the data directory are located. The option file can be either the my.ini file in your Windows directory or C:\my.cnf. For example, if you install MySQL in E:\mysql, the option group should look like this (note the use of forward slashes in the pathnames rather than backslashes): [mysqld] basedir=E:/mysql datadir=E:/mysql/data The following instructions assume that you install MySQL in C:\mysql. If you select a different installation directory, you'll need to change the pathnames in the commands shown in the examples. On Windows, you can choose from the MySQL server programs shown in the following table. (The Essentials package includes only the mysqld and mysqld-nt servers.)
In general, unless you need the debugging support provided by the mysqld-debug server, you are better off choosing one of the other servers. The mysqld-debug server uses much more memory and runs more slowly than the other Windows servers. The servers with -nt in their name support connections over named pipes when run on NT-based systems. However, named pipe support is disabled by default. To use this capability, you must add a line to the [mysqld] group in your option file: [mysqld] enable-named-pipe On Windows NT-based systems, any MySQL server can be installed to run as a service that starts automatically whenever Windows starts. For example, to install the mysqld-nt server as a Windows service, use this command:
C:\> C:\mysql\bin\mysqld-nt --install
If you use --install-manual rather than --install, the server is installed as a Windows service, but does not run automatically when Windows starts. You must use the Windows Services Manager or the net start command. If you install a MySQL server as a Windows 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 this command:
C:\> C:\mysql\bin\mysqld-nt --remove
To avoid interactions between the Services Manager and commands issued from the command 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. For example, to run mysqld-max, start it as follows:
C:\> C:\mysql\bin\mysqld-max
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 with the --console option. For example, to run mysqld this way, use the following command:
C:\> C:\mysql\bin\mysqld --console
When you run a MySQL server in console mode, 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. Note: When you run a MySQL server from the command line, you will not necessarily see another command prompt until the server exits. If this occurs, just open another console window in which to run MySQL client programs. If you have problems getting the server to run, check the Windows notes in the installation chapter in the MySQL Reference Manual. If you are installing MySQL for the first time on this machine, there are other actions that you'll probably want to perform at this point:
Instructions for performing these actions are given in Chapter 11. Current distributions of MySQL for Windows include the server-side help tables used for the help command of the mysql client. It should not be necessary to set up the help tables manually. However, the time zone tables that are needed for named time zone support may be missing or empty. To set up these tables, use the instructions in "Configuring Time Zone Support," in Chapter 11. If you are upgrading a MySQL installation, it is possible that the grant table structure has changed since your original installation. To update the tables to the current structure, use the instructions in "Dealing with Changes to Grant Table Structure," in Chapter 11. Installing Perl DBI Support on WindowsThe easiest way to install Perl modules under Windows is to get the ActiveState Perl distribution from www.activestate.com and install it. Then fetch and install the additional Perl modules that you need. The ppm (Perl Package Manager) program is used for this. C:\> ppm ppm> install DBI ppm> install DBD-mysql ppm> install CGI Installing Apache and PHP on WindowsApache 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 may 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. The PHP 5 binary distributions for Windows do not include MySQL support, so I recommend that you use the latest PHP 4 distribution. The Zip file distribution includes a go-pear program. Executing it installs the pear program that can be used to install and update PEAR modules, including the DB module. See the section "Installing Apache and PHP on Unix" earlier in this appendix for some notes on using pear. Installing Connector/ODBC on WindowsCurrent distributions of Connector/ODBC 3 are packaged as executable files with filenames of the form MyODBC-version-win.exe or MyODBC-version-win.msi. If you encounter an error such as "Problems while copying MFC30.DLL," while installing Connector/ODBC, 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 the installer again. After installing a Connector/ODBC 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 such as "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 of sources 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 the OK button. 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:
After configuring Connector/ODBC, you should be able to use ODBC-aware programs to access MySQL databases. For example, one common use for Connector/ODBC 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. Note that the tables you want to use must already exist before you can link to them.
After performing this procedure, the selected tables will be available through Access. |