JavaScript Editor Js editor     Website development 

Main Page

Previous Page
Next Page

Running MySQL on Windows and Windows NT

Unfortunately, you cannot truly know that MySQL has been successfully installed until you've been able to actually start the database server. Starting MySQL is a frequent place of problems and confusion, especially for the beginning or intermediate user. On the bright side, MySQL is very stable and reliable once you have it running, and it can remain up for months at a time without incident. If you run into difficulties in these steps, check the "Starting MySQL" section of Appendix A, "Troubleshooting." Or, as always, search the version of the MySQL manual that corresponds to the version of MySQL that you installed.

When it comes to running MySQL on Windows, the main decision is whether to run it as a service or not. If you are using an NT version of Windows, which includes Windows NT, 2000, 2003, and XP (and probably future versions of Windows, too), the recommendation is that you do run MySQL as a service. When you do so, MySQL will automatically start and stop when you turn on and shut down your computer. In fact, if, while running the MySQL Server Instance Configuration Wizard (Figure 2.1), you opted to install MySQL as a service and have it launch automatically, MySQL has already been started for you.

Figure 2.1. You may have the option of installing MySQL as a service when you configure the software.

If you cannot, or will not, run MySQL as a service, your instructions for controlling MySQL are listed first. Instructions specifically for starting and stopping MySQL as a service will be covered second.

When it comes to starting MySQL, it is very important that the MySQL server not be currently running. This may seem obvious, but trying to start MySQL when it's already running can lead to confusing error messages and is a common problem for MySQL newbies.

Running MySQL on Windows

Starting MySQL on a Windows operating system is very simple. The only real decision you'll need to make is which version of the MySQL servercalled mysqldto start. Depending upon what distribution of MySQL you installed, you will have some combination of the following choices (storage engines, which are referenced in these descriptions, are covered in Chapter 4, "Creating a MySQL Database"):

  • mysqld, the standard server, optimized with support for the InnoDB storage engine

  • mysqld-debug, compiled with full debugging enabled and support for both the InnoDB and BDB storage engines

  • mysqld-nt, similar to mysqld except more optimized for the NT family of Windows (NT, 2000, 2003, and XP)

  • mysqld-max, like the mysqld, but supporting every feature available

  • mysqld-max-nt, a cross between mysqld-nt and mysqld-max

As an average user, you may not see a difference when using any of these servers. As you make your decision, I'd recommend starting with the most basic optionmysqld or mysqld-ntand then making changes later to fine-tune MySQL's performance. Which MySQL server you use does not affect the reliability of the data stored, which is what matters in the end.

The only trick to manually starting MySQL on Windows is that you'll use a DOS prompt (also called a console window), which you may not previously have encountered. Most of these steps teach how to access a DOS prompt and execute applications from this command-line interface. Stopping MySQL makes use of the mysqladmin utility, which I'll also demonstrate.

To start and stop MySQL on Windows:

Decide which server you will use.

Review the preceding list of servers for the possible options. You can confirm which are available to you by looking at the bin directory located within the MySQL default installation folder (just open it in Windows Explorer). You aren't permanently tied to whatever you choose here, so don't sweat it too much, particularly as you're just getting your bearings.

Make sure MySQL is not currently running.

If MySQL is already running, the following steps will result in errors, which may be unintelligible. If you followed the instructions in Chapter 1, "Installing MySQL," MySQL is probably already running. You can stop an active MySQL process using the instructions later in this sequence.

Access the Start menu.

Select Run.

The Run window can be used to run any command or program.

In the Run window, type cmd (Figure 2.2), and press Enter or click OK.

Figure 2.2. Enter cmd in the Run window to access a DOS prompt.

The code cmd is short for command, which is a request for a command window (Figure 2.3). Note that your command window may not look quite the same as mine (by default it's white text on a black background, which doesn't look so swell in a book), and the prompt will likely differ.

Figure 2.3. A console window, also known as a DOS prompt, or command-line interface.

Move into the MySQL installation directory (Figure 2.4).

Figure 2.4. Move into the MySQL directory to more easily access its programs.

cd C:\"Program Files\MySQL\MySQL Server 5.0"

Because you may or may not be able to call the MySQL programs directly (depending upon your PATH, see the first tip), it's best to move into the MySQL directory and call the programs from there. To avoid conflicts with the spaces in the pathname (in Program Files and MySQL Server 5.0), quotes are used as needed. The easiest way to type all this is to type a few letters and then press Tab, letting the autocomplete feature fill in the rest of each directory's name. If you installed MySQL in a different location, you'll need to change the path here accordingly.

Start the server (Figure 2.5).

Figure 2.5. If the MySQL server started properly, you'll see messages like those here (or the like).

At the prompt, type the following and press Enter:

bin\mysqld --console

The important part here is just the mysqld, which is the MySQL server itself. If you want to use a different version of the server (see the earlier list of servers), change that reference.

The --console option means that all results will be displayed in the console window, which is useful, particularly for debugging purposes. You should leave the console window open for the time being (closing the window will attempt to shut down MySQL). If you are running a non-NT version of Windows (something other than Windows NT, 2000, 2003, or XP), mysqld will automatically run in the background and you are free to do whatever with the console window.

Confirm that MySQL is running (Figure 2.6).

Figure 2.6. The mysqlshow utility will show a list of available databases and is also a way to confirm that MySQL is running.

Repeat Steps 36 to bring up a new console window (if necessary) and move into the MySQL directory. Then, at the prompt, type the following and press Enter:

bin\mysqlshow -u root -p

When prompted, enter the MySQL root user password (if you have not yet established a root user password, for instance, during server configuration, omit the -p argument).

Stop the server (Figure 2.7).

Figure 2.7. Use mysqladmin to shut down MySQL. If the MySQL root user does not require a password, omit the -p.

At the prompt, type the following and press Enter:

bin\mysqladmin -u root -p shutdown

The mysqladmin utility can be used for many things, including stopping a running server. The -u root argument says that mysqladmin should perform the commandshutdownas the MySQL root user. When prompted, enter the root user password (if you have not yet established a root user password, for instance, during server configuration, omit the -p argument).

Start MySQL up again and begin administering your database.

See the remainder of this chapter for information on related MySQL utilities, creating users, and so forth.


  • If, while running the MySQL Server Instance Configuration Wizard (Figure 2.1), you opted to include the bin directory in the Windows PATH, then you can start MySQL by just using mysqld --console. This will be true no matter what directory you are currently in (within the console window).

  • Technically, on Windows, you could go straight into the bin directory and run your commands from there. The syntax demonstrated in the preceding steps is common on other operating systems, so I've used it for consistency's sake.

  • If you don't use the --console option when starting MySQL, all output will be written to an error log. This is fine, if not preferred, normally, but it's best to use the --console option the first couple times you start the server to make sure there are no problems. The error log would be stored in the data directory (C:\Program Files\MySQL\MySQL Server 5.0\data, by default), with a .err extension. It is readable in any text editor.

  • You may be able to invoke the mysqlshow and mysqladmin applications without specifying a user at all, but I think it's best to be explicit.

Running MySQL as a Service on Windows

If you are using an NT version of Windows, which covers Windows NT, 2000, 2003, XP, and probably all future versions as well, you can run MySQL as a service. As a service, MySQL can be controlled in two ways: by typing commands in a console window or by using the Windows Service Control Manager. If you would prefer to use the first method, access a DOS prompt (using the Steps 35 in the preceding set of instructions) and then enter NET START MySQL to start the service or NET STOP MySQL to stop it (Figure 2.8). You can do this no matter what directory you are currently in (in the console window). If MySQL will not start for some reason, you'll need to check the error log, found in the MySQL data directory, with a name ending in .err. This is viewable in any text editor.

Figure 2.8. Starting and stopping the MySQL service on Windows XP.

The other way you can control the MySQL service is to use Windows' built-in Services utility. I'll run through that process now, but the steps do assume that MySQL has been installed as a service (see the sidebar). The instructions I'll use will apply to Windows XP; you may need to make slight adjustments if you are using a different version of the operating system.

Installing MySQL as a Service

The easiest way to install MySQL as a service is to check the right box during the configuration process (see Figure 2.1). If MySQL is not already installed as a service, you'll have to use a console window. Bring one up and move into the MySQL installation directory (using Steps 36 in the preceding section of this chapter). At the prompt type

bin\mysqld --install

and press Enter.

If you would like MySQL to be available as a service but not have it automatically start and stop, you can use the --install-manual option instead. In such a case, you would use NET START MySQL and NET STOP MySQL to control it. To remove the MySQL service, use mysqld --remove at the DOS prompt.

To start and stop the MySQL service:

Click Start to bring up the Start menu.

Select Control Panel.

This brings up the Control Panel window.

Double-click the Administrative Tools Control Panel.

If you are in the Classic view in Windows XP (Figure 2.9), the Administrative Tools is immediately available. If you are in the Category view (Figure 2.10), you must first click Performance and Maintenance and then click Administrative Tools.

Figure 2.9. The Windows XP Control Panel, in Classic view. Double-click Administrative Tools here.

Figure 2.10. The Windows XP Control Panel, in Category view. Click Performance and Maintenance here.

In the Administrative Tools window (Figure 2.11), double-click Services.

Figure 2.11. The Windows list of shortcuts to Administrative Tools like Services.

In the Services window, click MySQL (Figure 2.12) to select it.

Figure 2.12. You can control the MySQL service using this Windows tool.

In this window you can see every available service. The current status of each is listed, along with its startup type (Automatic, Manual, Disabled).

Start the service.

You can either click the Start link (found to the left of the list of services, see Figure 2.12) or click the right-pointing triangle at the top of the window (which looks like a Play button).

Stop the service.

With the service started, you can either click the Stop link (Figure 2.13) or use the square button at the top of the window.

Figure 2.13. The links of options change when a service is running (compare with Figure 2.12).


  • It's recommended that you keep the Services window closed when installing MySQL or using NET START MySQL or NET STOP MYSQL commands.

  • If you right-click the MySQL service and select Properties from the contextual menu, you'll be able to tweak the MySQL service in other ways (Figure 2.14). You can adjust which version of mysqld is started by the service (see the Path to executable setting), change the Startup type, and so on.

    Figure 2.14. Each service has a list of properties that can be adjusted as warranted.

Previous Page
Next Page

JavaScript Editor Js editor     Website development