MySQL 8.0 – Who stopped mysqld and how long did it take ?

on

In MySQL 8.0.21, we can see who and how mysqld was stopped and when the process ended.

Let’s have a look at different scenarios in this article.

SHUTDOWN SQL statement

The first test is to initiate the shutdown of MySQL from a SQL client:

mysql> shutdown;

In the error log (log_error_verbosity is set to 2, the default), we can see:

2020-07-14T07:17:28.865274Z 10 [System] [MY-013172] [Server] 
          Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.21).
2020-07-14T07:17:31.258884Z 0 [System] [MY-010910] [Server] 
         /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.

We can easily identify when the server started the shutdown process and when it finished.

Stopping using systemd

Now let’s try to stop mysqld using the operating system control commands:

$ sudo systemctl stop mysqld

Once again, we can see that in the error log (identified by the global variable log_error):

2020-07-14T07:19:04.171507Z 0 [System] [MY-013172] [Server] 
          Received SHUTDOWN from user . Shutting down mysqld (Version: 8.0.21).
2020-07-14T07:19:06.167563Z 0 [System] [MY-010910] [Server] 
          /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.

We will get the same output when using the kill command like:

sudo killall mysqld
sudo kill $(pidof mysqld)
sudo kill -15 $(pidof mysqld)

Of course kill -9 won’t show anything in the error log.

RESTART SQL statement.

The new RESTART statement in MySQL 8.0 also logs the info in the error log:

2020-07-14T07:29:56.964342Z 8 [System] [MY-011086] [Server] 
          Received RESTART from user root. Restarting mysqld (Version: 8.0.21).
2020-07-14T07:29:59.352457Z 0 [Warning] [MY-010909] [Server] 
          /usr/sbin/mysqld: Forcing close of thread 8 user: 'root'.
2020-07-14T07:30:00.550514Z 0 [System] [MY-010910] [Server] 
          /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.

I hope this provides the missing information and will help the DBAs to identify when MySQL is flushing the dirty pages during a clean shutdown (innodb_fast_shutdown=0).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I deeply value the diversity of MySQL developers, users, community and my blog readers. I cannot agree the suffering, oppression, and systemic racism the Black community faces every day. Black lives matter.
recent
categories