SyntaxStudy
Sign Up
MySQL Read/Write Splitting
MySQL Intermediate 4 min read

Read/Write Splitting

Read/Write Split

Direct writes to the primary and reads to replicas to scale read-heavy workloads. Use a proxy (ProxySQL, MySQL Router) or application-level routing.

Example
// Laravel read/write split
// config/database.php
"mysql" => [
    "read"  => ["host" => ["replica1", "replica2"]],
    "write" => ["host" => "primary"],
    "sticky" => true,  // same connection for rest of request after write
    ...
]
// ProxySQL routes automatically based on query type
// SELECT → replicas, INSERT/UPDATE/DELETE → primary
Pro Tip

"sticky" ensures that writes are immediately readable in the same request — prevents stale read after write.