How to verify if a slave running in MySQL 5.7

Posted in: MySQL, Technical Track

Most people know that you can use SHOW SLAVE STATUS to verify if a slave is running in MySQL. Most people also know that you need to check both Slave_IO_Running and Slave_SQL_Running.

A few years ago, I responded to a question on dba.stackexchange.com on how to verify if a slave is running outside of SHOW SLAVE STATUS.

Prior to MySQL 5.7, you could get this information from SHOW GLOBAL STATUS:

Keep in mind that certain versions of 5.1 might give false information if the Slave_IO_Thread was not running.

But if you upgrade to MySQL 5.7 and your application relies on anything other than SHOW SLAVE STATUS output, it might be broken.

In MySQL 5.7, you would get this:

The reason is that MySQL is moving away from the information_schema GLOBAL_STATUS and SESSION_STATUS tables in preference for performance_schema.

The correct way to get the status of slave running in MySQL 5.7 outside of SHOW SLAVE STATUS is to use the new replication-based performance_schema tables:

An alternative to using the new performance_schema tables is to utilize a temporary compatibility variable: show_compatibility_56.

Conclusion

If your applications (monitoring or other) rely on checking that slaves are running by utilizing the information schema GLOBAL_STATUS table, upgrading to MySQL 5.7 will break it.

You have a few choices:

  • Use SHOW SLAVE STATUS directly and parse the output of Slave_IO_Running and Slave_SQL_Running. This requires application changes.
  • Use the new performance_schema replication tables performance_schema.replication_connection_status and performance_schema.replication_applier_status. This also requires an application change. And it should be noted that there are other tables for multi-master setups!
  • Use the compatibility variable show_compatibility_56. This is dynamic and doesn’t require application changes. However, this variable is immediately deprecated and will go away in a future release, so you will be required to update your application at some point anyway.
email

Author

Interested in working with Derek? Schedule a tech call.

About the Author

Derek Downey is the Director of Managed Services for the OpenSource Database practice at Pythian, helping to align technical and business objectives for the company and for our clients. Derek loves automating MySQL, implementing visualization strategies and creating repeatable training environments.

3 Comments. Leave new

Ronald Bradford
July 22, 2016 4:07 pm

Nice.

I also did not know about show_compatibility_56.

Reply

Does not work if you have performance-schema = OFF in your my.cnf file.

Reply

how about mysql 8?

Reply

Leave a Reply

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