Start MYSQL as a Windows Service

Source: Internet
Author: User
Tags mysql command line

In the NT family (Windows NT, 2000, XP, 2003), we recommend that you install MYSQL as a Windows service. When Windows starts or stops, MySQL also starts and stops automatically. You can also useNet

Command, or use graphicsServices
Tool to control the amysql server.

In Windows Control Panel (Windows 2000, XP and Server 2003 management tools)
).Services
Tool (WindowsService Control Manager
). We recommend that you disable this function when installing a live uninstall server from the command line.Services
Tool. This prevents many errors.

Before installing the MySQL Windows Service, run the following command to stop the currently running server:

C:/> C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqladmin -u root shutdown

Note:
If the MySQL Root User Account has a password, you need to call the commandC:/program files/MySQL Server 5.1/bin/mysqladmin-u root-P Shutdown
Enter the password as prompted.

This command calls the MySQL management toolMysqladmin
, Connect to the server and tell it to close the service. This command uses the MySQL Root User to connect. This is the default management account in the MySQL permission system. Note that users in the MySQL permission system are completely independent from those logged on to Windows.

Use this command to install the server

C:/> mysqld --install

If you only use the server name for InstallationMysqld

If there is a problem, try to use full path name for Installation


. For example:

C:/> C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqld --install

You can also add the path of the MySQL bin directory to the path environment variable of the Windows system:

· Right-click my computer on the Windows Desktop)
And select Properties ).

· Then, from the System Properties
Select the Advanced tab from the menu.
And then click environment variables.
(Environment variable)
Button.

· Select system variables (
System variables)
Path)
And then click Edit.
(Edit)
Button. Edit System variable (edit system variables) will pop up)
Dialog box.

· Place the cursor in the flag variable value
At (variable value)
Text. (UseEnd
Key to ensure that the cursor is at the end of the text ). Enter the full path of the MySQL bin directory (for example, C:/program files/MySQL Server 5.1/bin ), note that the path should be isolated from other values in the domain using semicolons. Close the dialog box and each dialog box at one time, and click OK.
Until all the opened dialog boxes are closed. You can enter the MySQL executable program name from any directory in the system at the DOS prompt to call the MySQL executable program without providing the path name. Including the server, MYSQL client, and all MySQL command line utilities, suchMysqladmin
AndMysqldump
.

· When running multiple MySQL servers on the same machine, you do not need to add the MySQL bin directory to Windows path.

Warning
: Special attention must be paid when editing the system path. accidental deletion or modification of the existing path value may cause system failure or even paralysis.

The service installation command does not start the server. Related commands are provided later in this section.

When installing the service, you can use the following parameters in MySQL 5.1:

· You can specify the service name directly after the -- install option. The default service name is MySQL.

· If the service name is provided, an option can be provided later. Generally, it should be defaults-file =File_name
Specifies the option file name, which should be read from when the server starts.

You can use a single option to replace -- defaults-file, but this is not recommended. -- Defaults-file is more flexible, because you can put multiple server startup options into the named option file.

· You can specify a -- local-service option after the service name. In this way, the LocalService Windows account is used when the server is running and only has limited system permissions. This account is only applicable to Windows XP or later versions. If the service name is followed by both -- defaults-file and -- local-service, the two can be discharged in any order.

For Windows MySQL server, determine the service name and option file used by the server according to the following rules:

· If the service name is not specified after the -- install option in the service installation command or the default service name (MySQL) is used ), the server uses the MySQL service name and reads the option from the [mysqld] group in the standard option file.

· In the service installation command, the service name specified after the -- install option is not the default service name (MySQL ). Read the option from the group with the same service name and read the option from the standard option file.

The server also reads the option from the [mysqld] Group of the standard option file. You can use the options in the [mysqld] group for all MySQL services, or use a group with the same service name for the server corresponding to the service name.

· If the -- defaults-file option is specified after the service name in the service installation command, the server only reads the option from the [mysqld] Group of the named file and ignores the standard option file.

For more complex examples, consider using the following command:

C:/> C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqld --install MySQL --defaults-file=C:/my-opts.cnf

In this command, the default service name (MySQL) is provided after the -- install option ). If the -- defaults-file option is not provided, this command allows the server to read from the [mysqld] Group of the standard option file. Because the -- defaults-file option is provided, the server only reads the option from the [mysqld] Group of the named file.

Before starting the MySQL serviceServices
Specify the startup Parameter options in the tool.

After the MySQL server is installed as a service, the service is automatically started when Windows is started. You can alsoServices
Tool to directly start the service or use commandsNet start MySQL
.Net
The command ignores the case sensitivity.

When running as a service,Mysqld

You cannot access the console window, so you cannot see any messages. IfMysqld
Not started. Check the error log to see if the server has written any messages that show the cause of the problem. The error log is located in the MySQL data directory (for example, C:/program files/MySQL Server 5.1/data). It is a file with a suffix. Err.

If the MySQL server is installed as a service and the service is running, the service is automatically stopped when Windows is disabled. You can also use the services tool,Net stop MySQL
Command orMysqladmin Shutdown
Command to manually stop the server.

If you do not want to automatically start the service during the boot process, you can also set the service to manual start mode. The method is to use the -- install-manual option instead of the -- install option:

C:/> C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqld --install-manual

To uninstall the server, use the command first if the service is running.Net stop MySQL
Stop the service. Then run the -- remove option to uninstall the service:

C:/> C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqld --remove

IfMysqld
It is not a service. You can start it from the command line. For details, see section 2.3.11, "Start MySQL from Windows Command Line"
.

If you encounter problems during installation, see Section 2.3.14, "Troubleshooting MySQL installation in Windows"
.

 

 

[Gengv] After I tried it, I started to see that it could not be started automatically. I made two changes:

1. In the Windows System directory, add the my. ini file. The content is as follows:

[Mysqld]
Basedir = D:/devsoft/MySQL/mysql-5.1.34/
Datadir = D:/devsoft/MySQL/mysql-5.1.34/data/

The path is set based on the actual MySQL location. This INI file is not required. You can try it again and again.

 

2. By changing the path, run mysqld -- install on the command line. Although the service is successfully added, the configuration file cannot be found at startup. As a result, I entered the bin directory of MySQL and executed mysqld -- install. Everything went smoothly and started successfully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.