Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start and shut down the MySQL server

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to start and shut down the MySQL server". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to start and shut down the MySQL server".

As a MySQL administrator, a common goal is to ensure that the server is running as much as possible so that clients can access it at any time. However, sometimes it is best to shut down the server (for example, if you are in the process of relocating a database, you do not want the server to update tables in that database). The requirement relationship between keeping the server running and occasionally shutting it down is not addressed in this article. But we can at least discuss how to start and stop the server so that you have the ability to do both.

The instructions in this chapter are for UNIX systems only.

Invoke the commands given in this chapter

For the sake of brevity, in most cases, programs such as mysqla d m i n, mysqldump, and so on do not give any-h,-u, or-p options in this chapter. The author assumes that you will call these programs with any options you need to connect to the server.

Run the MySQL server with an unprivileged user account

Before discussing how to start the server, consider which account should run when the server starts. The server can be started manually and automatically. If started manually, the server runs as the UNIX user (you happen to be registered as that user). That is, if the author registers with paul and starts the server, it will run as paul. If you use the s u command to switch the user to root and then start the server, the server runs as root.

However, you may not start the server manually most of the time. You will most likely schedule the server to run automatically as part of the standard startup process when the system boots. In UNIX, the startup process is performed by the system as the root user of UNIX, and any processes started during the process run with the privileges of root.

Two goals of the MySQL server startup process should be kept in mind:

Want the server to start as some non-root user. In general, unless a process really needs root access and mysql cannot, you should limit the capabilities of any process.

Want the server to always run as the same user. Conflicts arise when the server runs sometimes as one user and sometimes as another user. This will cause files and directories to be created under the data with different ownership, and even cause the server to not be able to access the database or table. Running the server consistently as the same user can avoid this problem.

To run the database as a standard, unprivileged user, follow these steps:

1) Select the account under which to run the server. Mysqld can be run as any user, but it is clear that it only creates a separate account for MySQL activities. You can also specify a specific group for MySQL. The author names the called users and groups mysqladm and mysqlg r p. If you use other names, replace them where there are mysqladm and mysqlgrp in this book

If you have installed MySQL under your account and do not have specific administrative privileges on the system, you can run the server under your own ID user. In this case, replace mysqladm and mysqlgrp with your own registration name and group name.

If you install MySQL under RedHat using the RPM file, the installer will automatically create an account under the name. This name should be used instead of mysqladm.

2) if necessary, use the account creation process commonly used by the system (a c count-c r e a t i o n) to create server accounts. This needs to be done as root.

3) shut down the server (if it is running).

4) modify the ownership of the data directory and any subdirectories and files so that mysqladm users own them. For example, if the data directory is / us r / l o c a l / v a r, the ownership of the mysqladm user can be set as follows:

# cd / usr/local/var move to the data directory

# chown-r mysqladmin.mysqlgrp sets ownership of all directories and files

5) modify the permissions for data directories and any subdirectories and files so that only mysqladm users can access them. Setting this way to avoid access by other people is a good security precaution. If the data directory is / us r / l o c a l / v a r, you can set everything you should have through mysqladm users by doing the following (you need to run these commands as root):

# cd / usr/local/var move to the data directory

# chmod-R go-rwx makes everything accessible only to mysqladm

Observe the symbolic connection when setting the ownership and manner of the data catalog and its contents. You need to track symbolic links and modify the ownership and manner of the file or directory you point to. If the directory where these connection files are located does not belong to you, doing so can cause trouble, so you must be a root user.

After completing the previous procedure, you should ensure that the server is always started, whether registered as mysqladm or root user. In the latter, make sure that the option of-user = mysqladm is specified so that the server can switch its user ID to mysqladm (this option can also be used during system startup).

-- the user option is added to the mysql of MySQL3.22. If your version is older than MySQL3.22, when you start the server and run as a root user, you can use the su command to instruct the system to run the server under the specified account. You need to read the manual page about su because the syntax for running the command as a specified user has been changed.

How to start the server

If you have determined the account under which to run the server, you can choose how to start the server. You can run the server manually from the command line or automatically during system startup. There are three main ways to start the server:

Call mysqld directly. This is perhaps the smallest method of command. Apart from explaining that mysqld-- help is a useful command that allows you to find options that you can use with other startup methods, the author does not intend to discuss it further.

Invoke the safe_mysqld script. Safe_mysqld attempts to determine the location of server programs and data directories, and then invokes the server with options that reflect those locations. Safe_mysqld redirects the standard error output of the server to an error file in the data directory and appears as a record. After starting the server, safe_mysqld also monitors the server and restarts it when it crashes. Safe_mysqld is commonly used in BSD-style versions of UNIX.

If you have started s a f e _ mysqld as root or in the system startup program, the error log will be owned by root. If you try to call s a f e _ mysqld as an unprivileged user, it may cause an "ownership denied" error. Delete the error file and try again.

Invoke the mysql.server script. By running s a f e _ mysqld. Mysql. Server, which starts the server. This script is recommended for systems that start / shut down the system using System V. The system includes several directories that contain scripts that are called when the machine logs in or exits a particular runtime. It can be called with the start or stop parameter to indicate whether you want the server to be started or shut down.

The safe_mysqld script is installed in the bin directory of the MySQL installation directory, or in the scripts directory of the MySQL source distribution. The mysql.server script is installed in the s h a r e / mysql directory of the MySQL installation directory, or in the support-files directory of the MySQL source distribution package. If you want to use it, you should copy it to the appropriate startup directory.

For BSD-style systems, there are several files in the / etc directory that start service during boot. The names of these files usually start with'rc', so there is likely to be a file called rc.local (or something like that) to start the local installation service. In such a system, you may want to add some lines to the rc.local file as follows to start the server (if the path is different from that on your system, modify it to s a f e _ mysqld):

If (- x / usr/local/bin/safe_mysqld); then

/ usr/local/bin/safe_mysqld &

Fi

For System V-style systems, install mysql. Exe by placing it in the appropriate boot directory under / etc. Server . If you run Linux and install MySQL from the RPM file, this is probably done. Otherwise, you should install the script in the main startup script directory and set the connection to it in the appropriate run-level directory. You can also make the script executable only to root users.

The layout of startup file directories varies from system to system, so a thorough review will be required to find out how the system organizes them. For example, in LinuxPPC, these directories are / etc/rc.d/init.d and / etc/rc. D / r c 3. D . The script should be installed as follows:

# cp mysql.server / etc/rc.d/init.d

# cd / etc/init.d

# chmod 500 mysql.server

# cd / etc/rc.d/rc3.d

# In-s.. / init.d/mysql.server S99mysql in Solaris, the main script directory is / e t c / init. D, the runtime directory is / e t c / r c 2. D, so the above command will be replaced with:

# cp mysql.server / etc/init.d

# cd / etc/init.d

# chmod 500 mysql.server

# cd / etc/rc2.d

# In-s.. / init.d/mysql.server s99mysql during system startup, the S99mysql script is called automatically using the start parameter.

If you have the chkconfig command (which is commonly used in Linux), you can use it to help install the mysql.server script instead of running the above command manually.

1. Specify startup options

If you want to specify additional startup options when starting the server, you can do so in two ways. You can modify the startup script (safe_mysqld or mysql. Net) that you use. Server) and specify these options directly on the command line that invokes the server You can also specify options in the options file. The author recommends that server options be specified in the global options file if possible. Typically, the location of this file is / e t c / my.cnf in UNIX and c:my.cnf in Windows (see Appendix E for details on using the options file).

Some types of information cannot be specified as options for the server. For these options, you may need to modify s a f e _ mysqld. For example, if the server does not correctly pick up the local time zone (local time zone) and return the time value in GMT, you can set the TZ environment variable to give the variable a hint. If you use safe_mysqld or mysql. Ser ver starts the server, and you can add the time zone setting to safe_mysqld. Locate the command line that starts the server and add the following command before the line:

TZ=US/Central

Export TZ

This command sets TZ to the US Central time zone. You need to use the time zone of the appropriate location. The syntax is S o l a r i s, and your system may be different. For example, another common syntax for setting the TZ variable is:

TZ=CST6CDT

Export TZ

If you modify the startup script, the next time you install MySQL (for example, upgrading to a newer version), you will lose those changes unless you previously copied the startup script somewhere else. After installing the new version, compare your script with the newly installed script to see what changes need to be made to rebuild.

Thank you for your reading, the above is the content of "how to start and shut down the MySQL server". After the study of this article, I believe you have a deeper understanding of how to start and shut down the MySQL server, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 251

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report