What is MySQL replication?

Why Interviewers Ask This

Mid-level MySQL / SQL roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

Answer

Replication is MySQL's mechanism for copying data from one server (source/primary/master) to one or more servers (replicas/slaves) in near real-time, creating identical copies of the database. How it works: the primary writes all changes to the binary log (binlog); replicas connect to the primary, read the binlog, and replay the changes in the same order. Replication uses: (1) Read scaling: route read queries to replicas, writes to the primary — distributes read load horizontally; (2) High availability: if the primary fails, promote a replica to primary (failover); (3) Backup: take backups from a replica without impacting the production primary; (4) Geographic distribution: put replicas closer to users in different regions. Replication types: asynchronous (default — primary doesn't wait for replica to confirm, possible data loss on failover), semi-synchronous (primary waits for at least one replica to acknowledge before committing — safer), synchronous (all replicas must confirm — very slow). Replication lag: replicas can fall behind under heavy write load — monitor with SHOW SLAVE STATUS\G, check Seconds_Behind_Master. MySQL Group Replication provides multi-primary replication.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex MySQL / SQL answers easy to follow.