Interview Q&A · questions with model answers

MySQL Interview Questions

Part of the study plan for: Data Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked How does a composite index work, and what is the leftmost-prefix rule?

    A composite index on (a, b, c) is sorted by a, then b, then c. It can serve queries that filter on a, on a and b, or on all three, but not on b or c alone. A range condition on a column stops later…

  2. Most asked How does MySQL replication work? Explain the binary log, asynchronous and semi-synchronous replication, and GTIDs.

    The source writes changes to the binary log; each replica's I/O thread copies events into its relay log, and SQL (applier) threads replay them. By default this is asynchronous; semi-synchronous…

  3. Most asked How do you back up a MySQL database, and how does point-in-time recovery work?

    Use physical backups (Percona XtraBackup, MySQL Enterprise Backup, snapshots) for large databases and logical backups (mysqldump, MySQL Shell dump utilities) for smaller ones or migrations.…

  4. Most asked How do you change the schema of a large MySQL table without downtime?

    Check whether the change can run with ALGORITHM=INSTANT or INPLACE (online DDL) in MySQL 8; otherwise use an online schema-change tool (gh-ost or pt-online-schema-change) that copies the table in…

  5. Most asked Explain INNER, LEFT and RIGHT joins. What is the classic LEFT JOIN mistake?

    INNER JOIN returns only matching rows; LEFT JOIN returns every row from the left table with NULLs where there is no match; RIGHT JOIN is the mirror image. The classic mistake is filtering the right…

  6. How does MVCC work in InnoDB?

    Each row stores the ID of the transaction that last changed it and a pointer into the undo log. A reader with a snapshot (read view) follows the undo chain back to the version that was committed…

  7. How do prepared statements prevent SQL injection?

    With prepared statements the SQL text and the values are sent separately; values are never parsed as SQL, so input like ' OR 1=1 -- is just a string. Escaping by hand is fragile; parameter binding…

  8. How does MySQL handle connections, and why do applications use connection pooling?

    By default MySQL uses one thread per connection. Each connection costs memory and context switching, and opening one costs a TCP handshake, TLS and authentication. Application-side pools reuse…

  9. How do NULLs behave in MySQL comparisons, indexes and unique constraints?

    NULL means unknown: NULL = NULL is not true, so use IS NULL. A UNIQUE index allows multiple NULLs. InnoDB indexes do store NULLs, so WHERE col IS NULL can use an index. Aggregates such as COUNT(col)…

  10. Is it worth indexing a low-cardinality column such as status or a boolean flag?

    On its own, usually not: if half the rows match, a full scan is cheaper than an index lookup per row, and the optimiser will ignore the index. It is worth it when the value you query is rare (status…

  11. A query shows 'Using filesort' and 'Using temporary'. What does that mean and how do you fix it?

    MySQL could not read rows in the needed order from an index, so it sorts them (filesort, in memory or on disk), and it needed an internal temporary table, usually for GROUP BY, DISTINCT or UNION.…

  12. How do you handle a 'hot row', such as a global counter updated on every request?

    Many transactions updating the same row serialise on its lock, limiting throughput. Spread the writes: shard the counter into N rows and sum them, buffer increments in Redis and flush periodically,…

  13. How do upserts work in MySQL, and why should you avoid REPLACE?

    INSERT ... ON DUPLICATE KEY UPDATE inserts a row or updates the existing one when a unique key conflicts, in one atomic statement. REPLACE deletes the conflicting row and inserts a new one, which…

  14. CHAR, VARCHAR or TEXT: which do you use?

    CHAR(n) is fixed length (padded), good for fixed-size codes; VARCHAR(n) is variable length with an n-character limit, the default choice; TEXT is for long content, cannot have a default value in…

Was this page helpful?

Report a mistake