Start and stop of MySQL server

Source: Internet
Author: User
Tags command line log

Running MySQL server as a non-privileged user

Before we discuss how to start the MySQL server, let's consider what user should be running the MySQL server. The server can be started manually or automatically. If you start it manually, the server starts with the user you logged on to UNIX (Linux), which runs with Paul if you log on to UNIX and starts the server, and if you switch to root with the SU command, and then start the server, it runs as root. However, most of the time you may not want to start the server manually, most likely you are arranging the MySQL server to start automatically when the system boots, as part of the standard boot process, which, under Unix, is performed by the UNIX user root of the system, And any processes running in the process are run with root permissions.

You should keep in mind the two goals of the MySQL server startup process:

You want to have the server run as a non-root user. Generally, you want to limit the ability to run a process, unless you really need root permission, and MySQL doesn't need it.

You want the server to always run with the same user, it is inconvenient to run the server with one user at a time and another with a different user, which creates a data directory with different owners and may cause the server to fail to access the database or table, depending on which user you are running. Unified use of the same user to run the server is you avoid this problem.

To run a server with an ordinary, unprivileged user, follow these steps:

Select a user to run the server, mysqld can run with any user. But conceptually clearer is the creation of a separate user for MySQL operations. You can also select a user group specifically for MySQL. This article uses Mysqladm and MYSQLGRP respectively as user names and user group names.

If you have installed MySQL under your account and don't have special administrative privileges on the system, you will probably run the server under your own user ID. In this case, use your own login name and user group instead of Mysqladm and MYSQLGRP.

If you install MySQL with the rpm file on Redhat Linux, the installation will automatically create an account named MySQL with this account instead of Mysqladm.

If necessary, create a server account with the system's usual process of creating a user, and you need to do it with root.
If the server is running, stop it.

Modify the Data directory and the owners of any subdirectories and files so that mysqladm users have them. For example, if the data directory is/usr/local/var, you can set the owner of the Mysqladm as follows (you need to run these commands with root):

#cd/usr/local/var
#chown-R MYSQLADM.MYSQLGRP

Modify the permissions of the data directory and any subdirectories and files so that they can be accessed only by Mysqladm users. If the data directory is/usr/local/var, you can set anything that is owned by Mysqladm:

# Cd/usr/local/var
# Chmod-r GO-RWX

When you set the owner and mode of the data directory and its contents, note the symbolic connection. You need to follow them and change the owners and patterns of the files or directories they point to. If the directory of the connection files is in a location that is not yours, you may have a problem with root identity.

After you have completed the above process, you should make sure that you always start the server when you log in as Mysqladm or root, and in the latter, determine the specified--user=mysqladm option so that the server can switch its user ID to Mysqladm (also applicable to the system startup process).

The--user option is introduced in MySQL 3.22, and if you have an older version, you can use the SU command to tell the system to run the server under a specific user when running as root.

Second, the way to start the server

After we have identified the account that is used to run the server, you can choose how to schedule the boot server. You can run it automatically from the command line, either manually or during the system boot process. There are three main methods for starting the server:
Call Mysqld directly.

This is probably the least common method and is not recommended for more use, so this article is not covered in detail.

Invokes the Safe_mysqld script.

Safe_mysqld attempted to determine the location of the server program and data directory. The server is then invoked with an option that reflects these values. Safe_mysqld the standard error device from the server to an error file in the data directory, making it a record. After the server is started, SAFE_MYSQLD also monitors it and restarts it if it dies. Safe_mysqld is commonly used in BSD-style UNIX systems.

If you start sqfe_mysqld with root or during system boot, the error log is owned by root, which may cause "permission denied" (Permission denied) errors when you later attempt to invoke Safe_mysqld with an unprivileged user. Delete the error log and try again.

Invokes the Mysql.server script.

This script starts the server by Safe_mysqld.mysql.server on the start and stop system that is intended for System V, which contains several script directories that are used when the machine enters or exits a given run level. It can use a start or a stop parameter to indicate whether you want to start or stop the server.

The Safe_mysqld script is installed in the bin directory of the MySQL installation directory, or can be found in the MySQL source code distribution scripts directory. The Mysql.server script is installed in the Share/mysqld directory under the MySQL installation directory or can be found under the Support_files directory where the MySQL source code is distributed. If you want to use them, you need to copy them to the appropriate directory.

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.