SyntaxStudy
Sign Up
MySQL Read Replicas for Scaling
MySQL Advanced 5 min read

Read Replicas for Scaling

Read Replicas

Distribute read traffic across replica servers to reduce load on the primary. Direct SELECT queries to replicas and write queries (INSERT/UPDATE/DELETE) to the primary.

Example
-- On primary: show replica status
SHOW MASTER STATUS;

-- On replica: check replication lag
SHOW SLAVE STATUS\G
-- Seconds_Behind_Master should be 0 or near 0

-- Application pattern:
-- $writeDb = connectTo('primary');
-- $readDb  = connectTo('replica');
Pro Tip

Replication lag means replicas may serve stale data — account for this in your app.