MySQL database startup and termination (1)

Source: Internet
Author: User

Because the MySQL server has a variety of installation and distribution capabilities and can run on a variety of operating platforms, it also has a variety of Start and Stop methods. You can use one of them according to your actual situation. When you install, upgrade, or maintain the system, you may need to start and terminate the Server Multiple times. You need to understand all aspects of starting and terminating the server.

Run the daemon directly

1. Methods you can use

Generally, you can have the following options to start the MySQL server. Their functions and usage are almost the same, so we will introduce them here:

Directly use the MySQL daemon mysqld to start the database system, especially the distribution on the Win32 platform. This is because mysql. server and other server scripts are not available on the Win32 platform.

By calling the safe_mysqld script, it accepts the same parameters as mysqld, tries to determine the correct options for mysqld, and then chooses to run it with those.

2. storage location of scripts or daemon

For binary distribution installation, the mysqld daemon is installed in the bin directory of the MySQL installation directory, or can be found in the libexec directory of MySQL source code distribution, the default value is/usr/local/libexec /. For rpm distribution, mysqld should be located in the program search PATH determined by the PATH variable, so it can be directly referenced.

Safe_mysqld is still a script and only exists in distribution on Unix platforms. The safe_mysqld script is installed in the bin directory of the MySQL installation directory, or can be found in the scripts directory of the MySQL source code distribution. For rpm distribution, the script should be located in the program search PATH determined by the PATH variable, so it can be directly referenced.

3. Why use the safe_mysqld script?

Safe_mysqld accepts the same parameters as mysqld, tries to determine the location of the server program and database directory, and then uses these locations to call the server. Safe_mysqld redirects the server's standard error output to the error file in the database directory, and the file exists as a record. After the server is started, safe_mysqld also monitors the server and restarts when it crashes. Safe_mysqld is usually used in BSD-style Unix versions.

If you have started safe_mysqld for root or in a System Startup Program, the error log will be owned by root. If safe_mysqld is called with a non-privileged user identity, the error of "Access Denied" (that is, "ownership Denied") may occur. In this case, you can delete the error file and try again.

Because of the safe_mysqld Script Function, using the safe_mysqld script is obviously more effective than directly starting the mysqld daemon.

4. Complete server startup process

For distribution on Unix platforms, if you start sqfe_mysqld as root or during system boot, error logs are owned by root, this may cause a "permission denied" permission error when you attempt to use a non-authorized user to call safe_mysqld.) Delete the error log and try again. Therefore, we recommend that you switch to a dedicated mysql user before starting the server.

The specific method is as follows:

Unix platform

$ Su mysql

$ Safe_mysql & or mysqld &, not recommended)

Win32 platform

C: \ mysql \ bin> mysqld -- standalone

Or C: \ mysql \ bin> mysqld-nt-standalone

If you use mysqld without installing mysql in a standard location, you usually need to provide the-basedir option for your database installation location.

$ Safe_mysqld -- basedir = "/path/to/mysql" & Unix platform)

C: \ mysql \ bin> mysqld -- basedir = "x:/path/to/mysql" (Win32 platform)

5. Use the safe_mysqld script to automatically start the server

You can also use safe_mysqld and mysqld to automatically start the server with the operating system. For Linux systems and BSD-style systems, such as FreeBSD and OpenBSD), several files in the/etc directory usually initialize the service during boot, these files usually have names starting with "rc" and may be named "rc. local files or similar things), specifically used to start locally installed services.

In such a system, you may add rows similar to the following to the rc. local file to start the server. If the directory of safe_mysqld is different in your system, modify it ):

If [-x/usr/local/bin/safe_mysqld]; then/usr/local/bin/safe_mysqld & fi

As a result, the database will be started as root during boot, which may cause problems and troubles in some cases. You can specify the -- user option, so you can modify the above Code:

If [-x/usr/local/bin/safe_mysqld]; then

/Usr/local/bin/safe_mysqld -- user = mysql -- datadir =/path/to/data &

Fi


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.