Start and Stop a Mysql Server (2)

Source: Internet
Author: User
Tags unix domain socket
Start and Stop a Mysql Server (2)

Start and Stop a Mysql Server (2)

3. Stop the server
To manually start the server, use MySQLadmin:

% Mysqladmin shutdown

To automatically stop the server, you do not need to do anything special. The BSD system generally stops the service by sending a TERM signal to the process. They either respond to it correctly or are roughly killed. When it receives this signal, mysqld uses termination as the response. For a System V-style System that uses mysql. server to start the server, the stop process uses a stop parameter to call the script and tell the server to terminate the process. Assume that you have installed mysql. server.

4. If you cannot connect to the server, how can you regain control over the server?

In some cases, you may manually restart the server because you cannot connect to it. Of course, this is a bit contradictory. Because you usually turn it off manually by connecting to the server, how can this happen.

First, the MySQL root password can be set to a value that you do not know. This may happen when you change the password, for example, if you accidentally enter an invisible control character when entering a new password. You may also forget the password.

Second, connecting to localhost is usually done through a Unix domain socket file, usually/tmp/mysql. sock. If the socket file is deleted, the local client cannot connect. This may occur when your system runs a cron task to delete temporary files under/tmp.

If you cannot connect because of the loss of the socket file, you can simply restart the server and recreate it. Because the server re-creates it at startup. The scam here is that you cannot establish a connection with a socket because it is gone, you must establish a TCP/IP connection, for example, if the server host is pit.snke.net, you can connect like this:

% Mysqladmin-p-u root-h pit.snke.net shutdown

If the socket file is deleted by a cron task, the problem repeats unless you modify the cron task or use one or more different Socket files, you can use the global options file to specify a different Socket. For example, if the data directory is/usr/local/var, you can add the following lines to/etc/my. in cnf, move the socket file there:

[Mysqld]
Socket =/usr/local/var/mysql. sock

[Client]
Socket =/usr/local/var/mysql. sock
Specify the path name for both the server and the customer so that they all use the same socket file. If you only set the path for the server, the client program will still expect to execute the socket in the original location, restart the server after modification, and create a socket in the new location.

If you forget the root password or have set it to a different value and cannot connect, You need to regain control of the server. You can set the password again:



Server interruption

If you use root to log on to the server host, you can use the kill command to terminate the server. You can use the ps command or find the server's PID file (usually in the data directory) to find the ID of the server process.

It is best to first try a normal kill that sends a TERM signal to the server to see if it will terminate the response normally. In this way, tables and logs are correctly cleared. If the server is blocked and does not respond to a normal termination signal, you can use kill-9 to force it to terminate. This is the final method, because there may be uncleared modifications, and you are at risk of putting the table in an inconsistent state.

If you use kill-9 to terminate the server, make sure that you use myisamchk and isamchk to check your table before starting the server.
Use the -- skip-grant-table option to restart the server.
This tells the server not to use the authorization table to verify the connection, which allows you to connect to the server as root without a password. After you have connected, change the root password.
Use mysqladmin flush-privileges to tell the server to start with the authorization table again
If you do not know Flash-privileges in mysqladmin, try reload.

5. run multiple servers

Most of them run a single MySQL server on a given machine, but in many cases, it is very useful to run multiple servers:

You may want to test a new version of a server and keep the production server you are running. In this case, you will run different server code.
The operating system generally limits the number of opened file handles for each process. If your system is difficult to raise this limit, running multiple servers is a way to solve the limit. In this case, you may run multiple instances of the unified server.
ISP often provides its customers with their own MySQL installation, and it is necessary to involve a separate server. In this case, you may run multiple instances of the same version or different versions, if different customers want different versions of MySQL.
Naturally, running multiple servers is much more complex than running only one server. If you install multiple versions, you cannot install everything in the same place. When the server is running, some parameters must or may be unique to each server, they include the Server installation path, the path name of its data directory, the TCP/IP Port and the path name of the UNIX domain socket, and the UNIX account used to run the server (if you no longer run all servers under the same account). If you decide to run multiple servers, pay attention to the parameters you use.

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.