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 stop the MySQL server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly introduces "how to start and stop the MySQL server". In the daily operation, I believe many people have doubts about how to start and stop the MySQL server. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to start and stop the MySQL server". Next, please follow the editor to study!

Running the MySQL server as an unprivileged user

Before we discuss how to start the MySQL server, let's consider as what user we should run the MySQL server. The server can be started manually or automatically. If you start it manually,

It, the server starts as the user you log in to Unix (), that is, if you log in to Unix with paul and start the server, it runs with paul; if you use the su command to switch to root, then

When the server is started, it runs as root. However, in most cases you may not want to start the server manually, and it is most likely that you arrange for the MySQL server to start automatically when the system boots

As part of the standard boot process, under Unix, the boot process is performed by the system's Unix user root, and any process running during the process runs with root privileges.

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

You want the server to run as some non-root user. In general, you want to limit the ability of any process to run, unless you do need root permissions, which MySQL does not.

If you want the server to always run as the same user, it is inconvenient to run the server with one user at this time and another user at other times, which results in files and directories

To be created under a data directory with different owners, and may cause the server to be inaccessible or table, depending on which user you run under. You avoid running the server with the same user.

Get rid of this problem.

For an ordinary unprivileged user to run the server, follow these steps:

Select a user to run the server, and d can run with any user. But it is conceptually clear to create a separate user for the MySQL operation. You can also do it especially for

MySQL selects a user group. This article uses mysqladm and mysqlgrp as the user name and user group name, respectively.

If you have installed MySQL under your account and do not have special administrative privileges on the system, you will probably run the server under your own user ID. In this case, use yourself

The login name and user group replace mysqladm and mysqlgrp.

If you install MySQL with a rpm file on RedHat Linux, the installation will automatically create an account called mysql instead of mysqladm.

If necessary, use the system's usual process of creating users to create a server account, which you need to do with root.

If the server is running, stop it.

Modify the owner of the data directory and any subdirectories and files so that the mysqladm user owns them. For example, if the data directory is / usr/local/var, you can set mys as follows

Owner of qladm (you need to run these commands as 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 only be accessed by mysqladm users. If the data directory is / usr/local/var, you can set it by mysqladm

Anything you have:

# cd / usr/local/var

# chmod-R go-rwx

When you set the ownership and mode of the data catalog and its contents, pay attention to symbolic links. You need to follow them and change the owner and mode of the file or directory they point to. If you connect the file

The directory is located in a place that does not belong to you, it will be troublesome, you may need root identity.

After you have completed the above process, you should make sure that the server is always started when logging in as mysqladm or root, and in the latter, be sure to specify the-- user=mysqladm option so that the server can

Its user ID switches to mysqladm (also applicable to the system startup process).

The user option was introduced in MySQL 3.22. If you have an older version, you can use the su command to tell the system to run the server under a specific user while running as root.

Second, the method of starting the server

After we have determined the account used to run the server, you can choose how to arrange to start the server. You can run it manually or automatically during system boot from the command line. For

There are three main ways to start the server:

Call mysqld directly.

This is probably the least commonly used method, and it is recommended that you do not use it too much, so this article will not cover it in detail.

Invoke the safe_mysqld script.

Safe_mysqld attempts to determine the location of server programs and data directories. The server is then invoked with options that reflect these values. Safe_mysqld relocates standard error devices from the server

To an error file in the data directory so that there is a record of it. After starting the server, safe_mysqld also monitors it and restarts it if it dies. Safe_mysqld is commonly used in B

SD style Unix system.

If you start sqfe_mysqld as root or during system boot, the error log is owned by root, which may guide you later when you try to call safe_mysqld with a non-privileged user

To the "permission denied" error, delete the error log and try again.

Invoke the mysql.server script.

This script starts the server by intentionally using safe_mysqld.mysql.server on the System V startup and stop system, which contains several entries in or out of the machine

A script directory that is clicked on at a given run level. It can use a start or stop parameter point 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 scripts directory where the MySQL source code is distributed. Mysql.server script installation on MySQL installation

It can be found in the share/mysqld directory under the directory or in 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

.

For BSD-style systems (FreeBSD,OpenBSD, etc.), there are usually several files under the / etc directory that initialize the service at boot time, usually with the name "rc", and

It is possible that a file called "rc.local" (or something like that) is specifically used to start locally installed services. On such a system, you might add a line similar to the following to r

Start the server in the c.local file (if the directory of safe_mysqld is different on your system, modify it):

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

/ usr/local/bin/safe_mysqld &

Fi

For System V-style systems, you can install it by placing mysql.server in the appropriate boot directory under / etc. If you run Linux and install it from a RPM file

Install MySQL, which is already done for you, otherwise install the script in the main startup directory and place the connection to it in the appropriate runtime directory. You can also make the script available only by root

Activate.

The directory layout of startup files varies from system to system, so you need to check to see how your system organizes them. For example, in Linux

On PPC, the directories are / etc/rc.d and / etc/rc.d/rc3.d, so you can install the script like this:

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

# cd / etc/init.d

# chmod 500 mysql.server

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

# ln-s.. / init.d/mysql.server S99mysql

On solaris, the main script directory is / etc/init.d, and the run-level directory is / etc/rd2.d, so the command looks like this:

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

# cd / etc/init.d

# chmod 500 mysql.server

# cd / etc/rc2.d

# ln-s.. / init.d/mysql.server S99mysql

When the system starts, the S99mysql script is automatically called with a start parameter. If you have the chkconfig command (available on Linux), you can use it to help install the mysql.server foot

Ben does not run the above command manually as above.

2.1 specify startup options

If you want to specify additional startup options when the server starts, you can do it in two ways. You can modify the startup script you use (safe_mysqld or mysql.server) and directly in the

Specify options on the line of the calling server, or in an options file. It is recommended that you specify options if possible in a global options file, which is usually located at / etc/my.cnf (Unix

) or c:my.cnf (Windows).

Some types of information cannot be specified as server options. You may need to modify the safe_mysqld for these. For example, if your server does not correctly select the local time zone and returns with GMT

To return to the time value, you can set the TZ environment variable to give it an indication. If you start the server with safe_mysqld or mysql.server, you can add a time zone setting to safe_mysqld

. Locate the line that starts the server and add the following command before the line:

TZ=US/Central

Export TZ

The syntax of the above command is Solaris, for other system syntax may be different, please refer to the relevant manual. If you do modify your startup script, remember that the next time you install MySQL

If you upgrade to a new version, your changes will be lost unless you first copy the startup script elsewhere. After installing the new version, compare the old and new versions of the script to see what you need to rebuild

Change.

2.2 check your watch at startup

In addition to scheduling your server to start when the system boots, you may want to install myisamchk and isamchk scripts to check your table before the server starts. You may be heavy after a breakdown.

It is possible that the table has been damaged, and checking it before startup is a good way to find problems.

3. Stop the server

To start the server manually, use mysqladmin:

% mysqladmin shutdown

To stop the server automatically, you don't have to do anything special. BSD systems generally stop service by sending a TERM signal to the process, and they either answer it correctly or are killed rudely. Mysq

Ld responds with termination when it receives this signal. For System V-style systems that start the server with mysql.server, the stop process will call the script with a stop parameter, informing

Tell the server to terminate, of course, assuming that you have installed mysql.server.

If you can't connect to the server, how to regain control of the server

In some cases, you may restart the server manually because you cannot connect to it. Of course, it's a bit of a contradiction. Because you usually turn it off manually by connecting to the server, so in this case

How to show up.

First, the MySQL root password can be set to a value you don't know, which may happen when you change the password, for example, if you accidentally type in an invisible

Control characters. You may also forget your password.

Second, the connection to localhost is usually done through a Unix domain socket file, usually / tmp/mysql.sock. If the socket file is deleted, the local customer cannot connect.

This may happen when your system runs a cron task to delete temporary files under / tmp.

If you can't connect because you lost the socket file, you can simply recreate it by restarting the server. Because the server recreates it when it starts. The scam here is

You can't make a connection with a socket because

At this point, the study on "how to start and stop the MySQL server" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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: 0

*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