Setup MySQL heartbeats for low and intermittent traffic databases
In low-traffic or intermittent databases, the log can become stale due to inactivity, which may cause the Connector to miss change events. Heartbeats (enabled by default) help mitigate this.To mitigate this further, a heartbeat table can be created in the source database which the heartbeat process — running within the Connector — periodically updates. This generates a change event in MySQL preventing the logs from becoming stale.
-- Create the streamkap schemaCREATE SCHEMA IF NOT EXISTS streamkap;-- Switch to the streamkap schemaUSE streamkap;-- Create the heartbeat table with id, text, and last_update fieldsCREATE TABLE streamkap_heartbeat ( id INT AUTO_INCREMENT PRIMARY KEY, text TEXT, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP);-- Grant permission to the Streamkap userGRANT SELECT, INSERT, UPDATE ON streamkap.streamkap_heartbeat TO STREAMKAP_USER;-- Insert the first row into the heartbeat tableINSERT INTO streamkap_heartbeat (text) VALUES ('test_heartbeat');