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 Why is InnoDB the default storage engine, and how does it differ from MyISAM?

    InnoDB is transactional (ACID), uses row-level locking and MVCC, supports foreign keys, and recovers automatically after a crash. MyISAM has none of these: it locks whole tables on writes and can be…

  2. Most asked What is the difference between utf8 and utf8mb4 in MySQL, and why does it matter?

    MySQL's old utf8 (an alias of utf8mb3) stores at most 3 bytes per character, so it cannot store emoji or some CJK characters; inserts fail or are truncated. utf8mb4 is real UTF-8 and is the default…

  3. Most asked AUTO_INCREMENT or UUID primary keys in MySQL?

    AUTO_INCREMENT BIGINT keys are compact and insert in order, which suits InnoDB's clustered index. Random UUIDv4 keys are 16+ bytes, insert randomly (page splits, poor cache locality) and enlarge…

  4. Most asked MySQL or PostgreSQL: how would you choose for a new project?

    Both are mature and handle most OLTP workloads well. PostgreSQL offers richer SQL and types (JSONB with GIN indexes, arrays, partial and expression indexes, extensions such as PostGIS and pgvector,…

  5. Optimistic or pessimistic locking: when do you use each in MySQL applications?

    Pessimistic locking (SELECT ... FOR UPDATE) locks rows before changing them, which suits high contention and short transactions. Optimistic locking adds a version column and updates with WHERE id =…

  6. DATETIME or TIMESTAMP: which should you use?

    TIMESTAMP stores a UTC instant and converts to and from the session time zone; its range ends in 2038. DATETIME stores the wall-clock value as given, without time-zone conversion, and supports years…

  7. When does table partitioning help in MySQL, and when does it not?

    Partitioning splits one table into parts by a key (RANGE, LIST, HASH, KEY). It helps when queries always filter on the partition key (partition pruning) and for data lifecycle: dropping an old…

  8. Should you use foreign keys in MySQL?

    Usually yes: InnoDB foreign keys guarantee referential integrity and catch application bugs. They do add work to writes (a lookup in the parent and locks on the parent row), and some very large or…

  9. What are the binary log formats (ROW, STATEMENT, MIXED), and which should you use?

    STATEMENT logs the SQL statements; ROW logs the actual row changes; MIXED uses statements unless a statement is unsafe. ROW is the default and recommended, because it replicates non-deterministic…

  10. Subquery or JOIN: which is faster in MySQL?

    It depends on the query and the version; MySQL 8 transforms many IN and EXISTS subqueries into semi-joins or anti-joins and optimises them like joins. Write the clearest correct query, then compare…

  11. What is the difference between DELETE, TRUNCATE and DROP?

    DELETE removes rows matching a condition, row by row, is transactional and fires triggers; TRUNCATE empties the whole table quickly by recreating it, resets AUTO_INCREMENT and cannot be rolled back;…

  12. Surrogate or natural primary keys?

    A surrogate key (AUTO_INCREMENT or a generated ID) has no business meaning and never changes; a natural key (email, ISBN, country code) has meaning but can change and is often longer. Most OLTP…

Was this page helpful?

Report a mistake