1

I am investigating an issue in an environment where MySQL is often restarted, by various actors (backups admins etc).

To make analysis saner, I need to know exactly when MySQL is (re)started.

Here is the current slow.log:

/usr/sbin/mysqld, Version: 5.5.27-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
/usr/sbin/mysqld, Version: 5.5.27-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
/usr/sbin/mysqld, Version: 5.5.27-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument

As you can see, there is no timestamp, I can only know that MySQL has been started 3 times that day, but I don't know when.

Question: How to make MySQL print a timestamp at each time it starts?

For unfortunate real-world reasons I can't get every single actor to reliably keep track of when they restart MySQL.

Nicolas Raoul
  • 319
  • 1
  • 5
  • 16

1 Answers1

1

You do not need to consult the log. mysqld can tell you.

For anyone running MySQL 5.6 and prior, or MySQL 5.7 in MySQL 5.6 compatibility mode

SELECT NOW() - INTERVAL variable_value SECOND MySQL_Started
FROM information_schema.global_status
WHERE variable_name='Uptime';

For everyone running MySQL 5.7

SELECT NOW() - INTERVAL variable_value SECOND MySQL_Started
FROM performance_schema.global_status
WHERE variable_name='Uptime';

EXAMPLE (MySQL 5.7.12 on my Windows Laptop)

mysql> SELECT NOW() - INTERVAL variable_value SECOND MySQL_Started
    -> FROM performance_schema.global_status
    -> WHERE variable_name='Uptime';
+----------------------------+
| MySQL_Started              |
+----------------------------+
| 2018-03-19 09:10:43.000000 |
+----------------------------+
1 row in set (0.00 sec)

As to why the time is not being printed, here is what I suspect

I do not believe mysqld_safe will print timestamps on mysqld restarts. If you really want mysqld_safe to print a timestamp on mysqld restarts, you can edit mysqld_safe (it is just a bash script) and place a line in the indefinite loop that echoes the date

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536