MySQL server heartbeat

Actively monitoring replication connectivity with MySQL’s heartbeat provides step-by-step instructions on activating the heartbeat option for master-slave replication that became available in v5.5, it’s worth a read.

Up until recently I haven’t seen much reason to upgrade my current farm of stock MySQL 5.1 servers on RHEL 6. A new project to make Openfire more highly available (a topic for another day) and actually running several MySQL master-slave instances in production for WordPress got me thinking about monitoring solutions. The above url came through in onse search.

The business case for at least upgrading to MySQL Server 5.5 (and possibly MariaDB) is made in the first paragraph of the post:

Until MySQL 5.5 the only variable used to identify a network connectivity problem between Master and Slave was slave-net-timeout. This variable specifies the number of seconds to wait for more Binary Logs events from the master before abort the connection and establish it again. With a default value of 3600 this has been a historically bad configured variable and stalled connections or high latency peaks were not detected for a long period of time or not detected at all. We needed an active master/slave connection check. And here is where replication’s heartbeat can help us.

Implementing the heartbeat option turns out to be very easy, once you’re database has been upgraded to 5.5 or newer.

All you need to do is connect to the slave server and turn it on.

mysql> stop slave;
mysql> change master to MASTER_HEARTBEAT_PERIOD = 1;
mysql> start slave;

The heartbeat then become effective, and will show up in a “slave status\G;” query.

Two new status variables become available after that:


(to get these do a “show slave status like ‘%heartbeat%’;”)

For me the choice isn’t very hard at all. The IUS Community repository already has MySQL 5.5 for RHEL 6 (and 5!), so upgrading can be done easily and cleanly.

As with all major component upgrades you should first do a mysqldump of the master and then re-initialize both nodes after completion — there’s just too much that can go wrong during any upgrade not to take that precaution.

Official doc on upgrading from MySQL 5.1 to 5.5 is on the MySQL site. I’ve blogged before on how to upgrade using the IUS repo, and the use of the mysql_upgrade script to let databases created under 5.1 work properly with 5.5. In general you’ll want to back up /etc/my.cnf and do a separate mysqldump of all databases, including mysql. While it should be possible to do the package upgrade against the existing data file in /var/lib/mysql (or wherever you maintain them), never procede without full backups. Also note that upgrading mysql may result in the upgrade of related packages, such as those for php. It’s always best to try things out in a test environment before doing so in production.

This entry was posted in Database, System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).