Correct understanding of the MySQL server shutdown process

Source: Internet
Author: User

The process of server shutdown can be summarized as follows:

1. Start and close the process

2. The server creates a thread to close the thread as needed.

3. The server stops receiving new connections.

4. The server terminates the current activity.

5. The storage engine is stopped or disabled.

6. log out of the server

The following is a more detailed description:

1. Start and close the process

You can enable server shutdown in multiple ways. For example, a user with the SHUTDOWN permission can execute the mysqladmin shutdown command. Mysqladmin can be used on all platforms that support MySQL. Other operating system-related shutdown start methods may also include: in Unix, when the SIGTERM signal is received, the server is shut down. For a server running as a service in Windows, it is disabled when the service manager closes it.

2. The server creates a thread to close the thread as needed.

Based on the method of starting to close, the server can create a thread to process the closing process. If the client needs to be closed, a thread is created. If the signal is closed after receiving the SIGTERM signal, the signal thread can be closed by itself, or a separate thread can be created. If the server tries to create a closed thread but cannot create it (for example, if the memory is exhausted), it will provide a diagnostic message in the error log:

     Error: Can't create thread to kill server

3. The server stops receiving new connections.

To prevent new activities from being started, the server stops receiving new client connections. It will close the network connection of frame listening: TCP/IP Port, Unix socket file, Windows Name pipe, and shared memory in Windows.

4. The server terminates the current activity.

For each thread related to the client connection, the connection to the client is interrupted, and the thread is marked as "killed ". When the thread notices such a flag, the thread terminates. The idle connection thread is terminated soon. The threads currently processing queries regularly check their statuses, And the termination time is long. For details about thread termination, see section 13.5.5.3 "KILL Syntax", especially the repair table or optimize table operation that kills the MyISAM TABLE.

The transaction is rolled back for threads that open the transaction. Note that if a thread is updating a non-transaction table, multiple row UPDATE or INSERT operations will partially UPDATE the table because the operation will be terminated before completion.

If the server is a master replication server, the Thread associated with the current connection is handled in the same way as other client threads. That is, each thread is marked as killed and will exit after the next check of its status.

If the server is a slave replication server, the activated I/O and SQL threads are stopped before the client thread is marked as killed. The SQL thread allows the current statement to be ended first (to avoid replication problems) and then stops. If the SQL thread is in the middle of the transaction, the transaction will be rolled back.

5. The storage engine is stopped or disabled.

At this stage, the table cache is cleared and all opened tables are closed.

Each storage engine performs any action required for the tables it manages. For example, MyISAM clears any pending table index write operations. InnoDB clears its buffer pool to the hard disk (unless innodb_fast_shutdown is 2), writes the current LSN to the table, and terminates its internal thread.

Note: For more exciting tutorials, please pay attention to the graphic tutorial channel of the customer's house,

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.