On the NT family (Windows NT, 2000, XP, 2003), the recommended way to run MySQL is to install it as a Windows service. With the MySQL server installed as a service, Windows starts and stops it server automatically when Windows starts and stops. A MySQL server installed as a service can also be controlled from the command line using NET commands, or with the graphical Services utility. Generally, to install MySQL as a Windows service you should be logged in using an account that has administrator rights.
The Services utility (the Windows Service Control Manager) can be found in the Windows Control Panel (under Administrative Tools on Windows 2000, XP, Vista and Server 2003). To avoid conflicts, it is advisable to close the Services utility while performing server installation or removal operations from the command line.
Before installing MySQL as a Windows service, you should first stop the current server if it is running by using the following command:
shell> C:\mysql\bin\mysqladmin -u root shutdown
If the MySQL root
user account has a
password, you need to invoke mysqladmin
with the -p
option and supply the password
when prompted.
This command invokes the MySQL administrative utility
mysqladmin to connect to the server and tell
it to shut down. The command connects as the MySQL
root
user, which is the default
administrative account in the MySQL grant system. Note that
users in the MySQL grant system are wholly independent from any
login users under Windows.
Install the server as a service using this command:
shell> C:\mysql\bin\mysqld --install
The service-installation command does not start the server. Instructions for that are given later in this section.
Before MySQL 4.0.2, no command-line arguments can be given
following the --install
option. MySQL 4.0.2 and
up offers limited support for additional arguments:
You can specify a service name immediately following the
--install
option. The default service name
is MySQL
.
As of MySQL 4.0.3, if a service name is given, it can be
followed by a single option. By convention, this should be
--defaults-file=
to specify the name of an option file from which the server
should read options when it starts.
file_name
The use of a single option other than
--defaults-file
is possible
but discouraged.
--defaults-file
is more
flexible because it enables you to specify multiple startup
options for the server by placing them in the named option
file.
For a MySQL server that is installed as a Windows service, the following rules determine the service name and option files that the server uses:
If the service-installation command specifies no service
name or the default service name (MySQL
)
following the --install
option, the server
uses the a service name of MySQL
and
reads options from the [mysqld]
group in
the standard option files.
If the service-installation command specifies a service name
other than MySQL
following the
--install
option, the server uses that
service name. It reads options from the group that has the
same name as the service, and reads options from the
standard option files.
As of MySQL 4.0.17, the server also reads options from the
[mysqld]
group from the standard option
files. This allows you to use the
[mysqld]
group for options that should be
used by all MySQL services, and an option group with the
same name as a service for use by the server installed with
that service name.
If the service-installation command specifies a
--defaults-file
option after
the service name, the server reads options only from the
[mysqld]
group of the named file and
ignores the standard option files.
As a more complex example, consider the following command:
shell> C:\mysql\bin\mysqld --install MySQL --defaults-file=C:\my-opts.cnf
Here, the default service name (MySQL
) is
given after the --install
option. If no
--defaults-file
option had been
given, this command would have the effect of causing the server
to read the [mysqld]
group from the standard
option files. However, because the
--defaults-file
option is
present, the server reads options from the
[mysqld]
option group, and only from the
named file.
You can also specify options in Start parameters in the Windows Services utility before you start the MySQL service.
Prior to MySQL 4.0.17, a server installed as a Windows service
has problems starting if its path name or the service name
contains spaces. For this reason, with older versions, avoid
installing MySQL in a directory such as C:\Program
Files
or using a service name containing spaces.
Once a MySQL server has been installed as a service, Windows starts the service automatically whenever Windows starts. The service also can be started immediately from the Services utility, or by using a NET START MySQL command. The NET command is not case sensitive.
When run as a service, mysqld has no access
to a console window, so no messages can be seen there. If
mysqld does not start, check the error log to
see whether the server wrote any messages there to indicate the
cause of the problem. The error log is located in the MySQL data
directory (for example, C:\mysql\data
). It
is the file with a suffix of .err
.
When a MySQL server has been installed as a service, and the
service is running, Windows stops the service automatically when
Windows shuts down. The server also can be stopped manually by
using the Services
utility, the NET
STOP MySQL command, or the mysqladmin
shutdown command.
From MySQL 3.23.44 on, you have the choice of installing the
server as a Manual service if you do not
wish the service to be started automatically during the boot
process. To do this, use the --install-manual
option rather than the --install
option:
shell> C:\mysql\bin\mysqld --install-manual
To remove a server that is installed as a service, first stop it
if it is running by executing NET STOP MySQL.
Then use the --remove
option to remove it:
shell> C:\mysql\bin\mysqld --remove
For MySQL versions older than 3.23.49, one problem with
automatic MySQL service shutdown is that Windows waited only for
a few seconds for the shutdown to complete, and then killed the
database server process if the time limit was exceeded. This had
the potential to cause problems. (For example, the
InnoDB
storage engine would have to perform
crash recovery at the next startup.) Starting from MySQL
3.23.49, Windows waits longer for the MySQL server shutdown to
complete. If you notice this still is not enough for your
installation, it is safest not to run the MySQL server as a
service. Instead, start it from the command-line prompt, and
stop it with mysqladmin shutdown.
This change to tell Windows to wait longer when stopping the
MySQL server works for Windows 2000 and XP. It does not work for
Windows NT, where Windows waits only 20 seconds for a service to
shut down, and after that kills the service process. You can
increase this default by opening the Registry
Editor
(\winnt\system32\regedt32.exe
) and editing
the value of WaitToKillServiceTimeout
at
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
in the Registry tree. Specify the new larger value in
milliseconds. For example, the value 120000
tells Windows NT to wait up to 120 seconds.
If mysqld is not running as a service, you can start it from the command line. For instructions, see Section 2.3.10, “Starting MySQL from the Windows Command Line”.
Please see Section 2.3.13, “Troubleshooting a MySQL Installation Under Windows”, if you encounter difficulties during installation.
User Comments
Be nice and do what it says. READ the error log.
The system error 1067 seems generic. If your problems says something like:
InnoDB: Error: log file .\ib_logfile{0,1} is of different size 0 0 bytes
InnoDB: than specified in the .cnf file 0 10485760 bytes!
050729 12:07:40 [ERROR] Can't init databases
050729 12:07:40 [ERROR] Aborting
Go ahead and delete both files. Yes, BOTH. They will be recreated with the right size, and the server will star cleanly.
I am happy to report that MySQL Server 5.0 installs and runs correctly on Windows Vista (December 05 CTP).
I installed using the msi download. Configuration failed initially because of a permissions issue but re-running the configuration tool from a cmd prompt with "run elevated" let me continue through the my.ini config and started the MySQL service.
Ok this is the way I installed mysql in my windows xp.
-downloaded the mysql-noinstall-5.0.20-win32.zip
-unziped it under c:\mysql. now my new path to mysql is: C:\mysql\mysql-5.0.20-win32
- I added the C:\mysql\mysql-5.0.20-win32\bin into my windowsxp path.
- started the server for the first time as I mentioned in section:
2.3.9. Starting the Server for the First Time
- Added the mysql as a service to windowsxp with using one of pre-configured ".ini" (option file, see 2.3.7. Creating an Option File) files in "C:\mysql\mysql-5.0.20-win32" path.
as the following:
C:\mysql\mysql-5.0.20-win32\bin>mysqld-nt --install mysql5
--defaults-file=C:\mysql\mysql-5.0.20-win32\my-small.ini
- then test the service by using:
C:\mysql\mysql-5.0.20-win32\bin>mysqlshow -u root mysql
>>> resutl <<<
Database: mysql
Watch out for windows defender blocking mysqld --install.
took me a minute, but as I was just tinkering after a webcast with --log="path" on my install and it worked fine before I tracked it down in event log.
(allow in control panel->system explorer/windows defender)
I ran into some headaches trying to install a 5.0 instance from the mysql-noinstall-5.0.37-win32.zip as a Windows Service.
I followed the instructions which said to run a test first with the --console, which worked fine, but then when I tried to start it as a service it would complain about not being able to find ibdata1. After some experimentation I discovered that the key is to change the group of the files in the data directory, mysql subdirectory, and files in mysql subdirectory to SYSTEM.
I have some more testing to do, but it seems OK now
In case you receive "The system cannot find the file specified", remember that you have to install the service with the absolute path, in my case "C:\mysql\bin\mysqld --install". I added the \bin to the windows path, and I was installing the service only with "mysqld --install".
As mentioned earlier by another user, I fell into the trap of adding MySQL to start as a service via a command like
C:\> mysqld --install
The service is reported as being installed successfully, however, under the Services panel it shows the executable path as 'C:\mysqld' when in fact it is located under 'C:\mysql\bin'. I was working under the assumption that the mysql\bin directory had been added to the system PATH variable, but really you need to use absolute file paths when installing services. In my case, I used;
C:\> C:\mysql\bin\mysqld --install MySQL --defaults-file=C:\mysql\my.ini
This starts the service automatically with Windows bootup, and will load the my.ini configuration file which you have to place within the mysql directory. For the first time however, you will need to start the mysql service manually, since the earlier command makes mysql start and end with windows shutdowns and restarts.
net start mysql
If you have problems installing the service on Windows Vista, just run the normal install and add the service manually with the following command:
use the sc create command in a dos window to add the service:
sc create MySQL start= auto DisplayName= MySQL binPath= c:\program files\mysql\mysql server 5.1\bin\mysqld.exe
then if you need to alter any parameters, use the administrative tools/services utility
If you have trouble starting the MySQL Administrator after you upgrade, it's because the upgrade changed the registry setting that identifies your configuration file. This has happened to me on every upgrade in the 5.x series over the past year.
See this excellent post by Michael Imhoff to fix it:
http://michael.omnicypher.com/2008/11/mysql-configuration-with-adobe.html
(You'll use your own INI file, of course.)
Another "got-ya"... Make sure your my.ini file is in your MySQL directory, and the variables are pointing to the correct directories.
Add your own comment.