Friday, November 22, 2013

What Time did MySQL Start?

Time MySQL Server Started



From a mysql client just execute the following to see the date and time the server was started.

select now() - interval (variable_value/60/60/24) day -- \
from information_schema.global_status -- \
where variable_name='Uptime';

From the shell, this will provide the same information.

mysql -uroot -p -A -s  -e"select now() - interval (information_schema.global_status.VARIABLE_VALUE/60/60/24) day -- \"from information_schema.global_status where variable_name='Uptime';"


Sometime you may run into having to restart the mysqld under pressure. And it will not come up.  

One cause is the my.cnf file is modified some time after startup with a bad setting. You could use the results from the commands above and compare that to

stat /etc/my.cnf

to see if any changes were made to my.cnf that might prevent the server from re-starting.


4 comments:

  1. How about to type word status in your mysql client? It's shorter, nicely formated in days hors seconds as well.

    ReplyDelete
  2. Egor: That's a nice command to know. But it doesn't get you the date and time it started, rather it tells you how many days, hours, seconds since it was started. Also, you may want to find out via MySQL Workbench or through an application.

    ReplyDelete
  3. The pt-config-diff from the Percona Toolkit is also very helpfull to compare the running configuration against the stored configuration.

    ReplyDelete
  4. Slightly simplifying your query:

    select now() - interval global_status.variable_value second from information_schema.global_status where variable_name='Uptime';

    ReplyDelete