MySQL server shutdown process

Source: Internet
Author: User
Tags exit terminates thread

The server shutdown process can be summarized as:

1. Start shutdown process

2. Server to create shutdown thread

3. Server stops receiving new connections

4. The server terminates the current activity

5. Storage engine is stopped or closed

6. Server exit

The following is a more detailed description:

1. Start shutdown process

You can start the shutdown of the server in several ways. For example, a user with shutdown permissions can execute the mysqladmin shutdown command. Mysqladmin can be used on all platforms that support MySQL. Other operating system-related shutdown starting methods may also be: In Unix, when the sigterm signal is received, the server shuts down. For a server running as a service in Windows, shut down when the service manager makes it shut down.

2. Server to create shutdown thread

Depending on how the shutdown was started, the server can create a thread to handle the shutdown process. If the client needs to close, a shutdown thread is created. If the sigterm signal is closed, the signal thread can shut itself down or create a separate thread to complete. If the server tries to create a shutdown thread and cannot create it (for example, if memory is exhausted), it gives a diagnostic message in the error log:

Error: Can't create thread to kill server

3. Server stops receiving new connections

The server stops receiving new client connections to prevent new activity from starting during the shutdown process. It will turn off the network connections it listens to: TCP/IP Ports, UNIX sockets files, Windows Named Pipes, and shared memory in Windows.

4. The server terminates the current activity

For each thread associated with the client connection, the connection to the client is interrupted and the thread is marked as "killed." The thread terminates when the thread notices such a tag. The thread of the idle connection terminates quickly. The threads that are currently processing the query periodically check their state for a longer time to terminate. For more information about thread termination, see section 13.5.5.3, "kill syntax," especially about repair table or optimize table operations on MyISAM tables.

For a thread that has open transactions, the transaction is rolled back. Note that if a thread is updating a non-transactional table, a multiline update or insert will cause the table to be partially updated because the operation terminates before it completes.

If the server is the primary replication server, the threads associated with the currently connected server are handled in the same way as other client threads. That is, each thread is marked for killing, and will exit after the next check on his status.

If the server is from a replication server, the activated I/O and SQL threads are stopped before the client thread is marked for killing. The SQL thread allows you to end its current statement (to avoid causing replication problems) and then stop. If the SQL line one thread is at the middle of the transaction, the transaction rolls back.

5. Storage engine is stopped or closed

At this stage, the table cache is emptied and all open tables are closed.

Each storage engine performs any action required by the table it manages. For example, MyISAM empties any pending table index writes. InnoDB empties its buffer pool onto the hard disk (unless the Innodb_fast_shutdown is 2), writes the current LSN to the table, and terminates its internal thread.

6. Server exit

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.