2014/04/16

mysql shutdown

■support by any Platform:
    mysqladmin shutdown
・if shutdown was requested by a client,a shutdown thread is created.
・shutdown is the result of receiving a SIGTERM signal, the signal thread might handle shutdown itself



■The server stops accepting new connections.
To prevent new activity from being initiated during shutdown, the server stops accepting new
client connections by closing the handlers for the network interfaces to which it normally listens for
connections: the TCP/IP port, the Unix socket file, the Windows named pipe, and shared memory on
Windows.


■The server terminates current activity.
For each thread associated with a client connection, the server breaks the connection to the client and
marks the thread as killed. Threads die when they notice that they are so marked. Threads for idle
connections die quickly. Threads that currently are processing statements check their state periodically
and take longer to die.

For threads that have an open transaction, the transaction is rolled back. Note that if a thread is
updating a nontransactional table, an operation such as a multiple-row UPDATE or INSERT may leave
the table partially updated because the operation can terminate before completion

If the server is a master replication server, it treats threads associated with currently connected slaves
like other client threads. That is, each one is marked as killed and exits when it next checks its state.
If the server is a slave replication server, it stops the I/O and SQL threads, if they are active, before
marking client threads as killed. The SQL thread is permitted to finish its current statement (to avoid
causing replication problems), and then stops.

If the slave is updating a nontransactional table when it is forcibly killed, the slave's data may become
inconsistent with the master.

■The server shuts down or closes storage engines.
At this stage, the server flushes the table cache and closes all open tables.
Each storage engine performs any actions necessary for tables that it manages. For example, MyISAM
flushes any pending index writes for a table. InnoDB flushes its buffer pool to disk (starting from 5.0.5:
unless innodb_fast_shutdown is 2), writes the current LSN to the tablespace, and terminates its
own internal threads.

■mysqld ? The MySQL Server
■mysqld_safe ? MySQL Server Startup Script、mysqld_safe adds some safety features such as restarting the server when an error occurs and logging runtime
information to an error log file.