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 What is a clustered index in InnoDB, and why does primary key choice matter so much?

    InnoDB stores table rows inside the primary key B-tree (the clustered index), ordered by primary key. Every secondary index stores the primary key value as its row pointer, so lookups through a…

  2. Most asked What are the transaction isolation levels, and which does InnoDB use by default?

    READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE. InnoDB defaults to REPEATABLE READ: a transaction's consistent reads see a snapshot taken at its first read, and locking reads use…

  3. Most asked What are gap locks and next-key locks, and why do they surprise developers?

    A gap lock locks the space between index records so other transactions cannot insert into it; a next-key lock is a record lock plus the gap before it. InnoDB uses them under REPEATABLE READ for…

  4. Most asked What are window functions, and give an example where they help.

    Window functions (MySQL 8.0+) compute values across a set of rows related to the current row without collapsing them like GROUP BY: running totals, rankings, moving averages, previous/next values…

  5. Most asked What is the InnoDB buffer pool, and how do you size it?

    The buffer pool is InnoDB's in-memory cache of data and index pages. Reads and writes go through it, so most performance depends on the working set fitting in it. On a dedicated database server it…

  6. What is a covering index?

    An index that contains every column a query needs, so MySQL answers the query from the index alone without looking up the full row. EXPLAIN shows Using index in the Extra column.

  7. What do SELECT ... FOR UPDATE, FOR SHARE, NOWAIT and SKIP LOCKED do?

    FOR UPDATE takes exclusive locks on the rows read, so others cannot modify or lock them until you commit; FOR SHARE takes shared locks (others can read-lock but not modify). NOWAIT fails immediately…

  8. What does EXPLAIN ANALYZE add over EXPLAIN?

    EXPLAIN ANALYZE executes the query and prints the iterator tree with estimated versus actual rows, loops, and time per step. It shows where the optimiser's estimates are wrong and which step takes…

  9. What are CTEs and recursive CTEs?

    A common table expression (WITH name AS (...)) names a subquery for readability and reuse within one statement; a recursive CTE references itself to walk hierarchies such as category trees or org…

  10. What is ONLY_FULL_GROUP_BY and why did queries break when it was enabled?

    With ONLY_FULL_GROUP_BY (default since 5.7) every selected column must be in the GROUP BY, aggregated, or functionally dependent on the grouped columns. Older MySQL allowed SELECT name, MAX(score)…

  11. What do innodb_flush_log_at_trx_commit and sync_binlog control?

    They control durability versus write speed. innodb_flush_log_at_trx_commit=1 and sync_binlog=1 (the defaults) flush the redo log and binary log to disk at every commit, so committed transactions…

  12. What is InnoDB Cluster / Group Replication?

    Group Replication is a plugin that replicates transactions between a group of servers using a consensus protocol, so a transaction commits only when a majority agrees. InnoDB Cluster combines it…

  13. What is strict SQL mode, and why should it be on?

    Strict mode (STRICT_TRANS_TABLES, on by default) makes MySQL reject invalid or out-of-range values instead of silently truncating or converting them, for example inserting a 300-character string…

  14. What are the redo log and the doublewrite buffer for?

    The redo log records changes before they are applied to data files (write-ahead logging), so after a crash InnoDB replays it to recover committed transactions. The doublewrite buffer writes pages to…

  15. What happened to the MySQL query cache?

    It was removed in MySQL 8.0. It cached result sets by exact query text, but every write to a table invalidated all cached results for that table, and its global mutex became a bottleneck on…

  16. What are the pros and cons of stored procedures and triggers?

    They run logic inside the database, close to the data, which reduces round trips and can enforce rules for every client. But they are harder to version, test, debug and deploy than application code,…

  17. What are invisible indexes and descending indexes in MySQL 8?

    An invisible index is maintained but ignored by the optimiser, so you can test the impact of dropping an index safely and make it visible again instantly. Descending indexes store keys in descending…

  18. What are optimizer histograms in MySQL 8?

    Histograms (ANALYZE TABLE t UPDATE HISTOGRAM ON col) record the distribution of values in a column so the optimiser can estimate selectivity for columns without indexes, or with skewed data, leading…

Was this page helpful?

Report a mistake