Why a MySQL Replica Core Hits 100% CPU and How Adding a Primary Key Fixes It
A MySQL replica was consuming an entire CPU core due to single‑process replication, and analysis of binlog and InnoDB status revealed heavy row locks on a table without a primary key, which was resolved by adding an auto‑increment ID, dropping CPU usage to 3% and eliminating replication lag.
Problem Description
During a customer inspection, a MySQL replica showed 100% CPU usage on a single core while the master had no slow write queries, indicating the replica’s single‑process replication was consuming all CPU.
Investigation Steps
1. Examine the binlog to see what statements are being replayed, using the parsebinlog tool from the mysql-binlog-statistic repository.
git clone https://github.com/wubx/mysql-binlog-statistic.git
cd mysql-binlog-statistic/bin/
parsebinlog /u1/mysql/logs/mysql-bin.000806The output highlighted a table xx_db.xxtable with roughly 100 k DELETE and 100 k INSERT operations per day.
2. Verify the replication status on the replica:
show slave status\G3. Check InnoDB lock information on the replica:
show engine innodb status\G;The monitor output listed many row‑level locks on xx_db.xxtable, all belonging to a single transaction and showing “TOO MANY LOCKS PRINTED”. The table lacked a primary key, causing InnoDB to generate a hidden clustered index ( GEN_CLUST_INDEX) and leading to extensive page splits and low concurrency.
Solution
Adding an explicit primary key to xx_db.xxtable resolves the issue. An auto‑increment integer column was added, which eliminated the hidden clustered index, reduced lock contention, and dropped the replica’s CPU usage from near‑full to about 3 %.
Result
After the primary key addition, replication proceeded normally with no observed lag over a full day of monitoring.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
