MySQL Interview Questions for Data Engineers and Analysts
MySQL questions actually asked in Indian data interviews — from services screening rounds on joins and stored procedures to GCC deep-dives on InnoDB internals, EXPLAIN plans, and replication. Every answer is written the way a strong candidate would say it.
By Durgesh Yadav — Senior Data Engineer @ 7-Eleven · Updated 2026-07-25. Preparation guidance, not a hiring guarantee.
What MySQL topics are asked in data engineering interviews?
Indian data interviews test MySQL on indexing (composite, covering, leftmost prefix), reading EXPLAIN output, InnoDB internals (clustered index, MVCC, redo log), transactions and isolation levels, joins, replication with binlog and GTID, and MySQL 8 window functions. Services companies stress joins and stored procedures; product companies and GCCs probe EXPLAIN plans and index design depth.
The MySQL round is rarely trivia — it is SQL writing plus "why is this query slow". Services-company screens lean on joins, aggregation edge cases, and stored routines; product companies and GCCs push into EXPLAIN output, index design, and InnoDB behaviour under concurrency.
SQL writing: joins, GROUP BY edge cases, top-N per group, de-duplication
Performance: EXPLAIN columns, index selection, the leftmost-prefix rule
Internals: clustered index, isolation levels and locking, replication flow
Indexing and EXPLAIN: where candidates get separated
Most rejections in MySQL rounds come from failing to reason about indexes, not from failing to write SQL. If you can read an EXPLAIN plan aloud and say what you would change, you are ahead of most of the pipeline.
type=ALL on a large table is a full scan — propose the fix before being asked
A composite index on (a,b,c) serves a / a,b / a,b,c; a range on b stops use of c
Extra column: "Using index" = covering; "Using filesort" and "Using temporary" = optimization targets
InnoDB, transactions, and replication
Senior rounds go one layer down: how InnoDB actually delivers ACID and how changes reach replicas. You do not need source-code depth — you need the correct causal story for durability, phantom prevention, and failover.
Replication ships the binlog (ROW format) to replicas; GTID makes failover and repointing sane
Question bank
16 interview questions with answers
Real questions from beginner to advanced, each with a concise model answer — practice them, then rehearse live in a mock interview.
EasyWhat is the difference between InnoDB and MyISAM, and which should you use?
InnoDB supports transactions, row-level locking, foreign keys, and crash recovery via the redo log, and stores rows in a clustered index; MyISAM has only table-level locking, no transactions, and no foreign-key enforcement. InnoDB has been the default since MySQL 5.5, and in MySQL 8 even the data dictionary is InnoDB. Use InnoDB for everything new — MyISAM survives only in legacy read-only workloads.
EasyWhat is the difference between WHERE and HAVING?
WHERE filters rows before grouping and cannot reference aggregates; HAVING filters after GROUP BY and can use aggregates like COUNT(*) or SUM(). Filtering in WHERE is cheaper because rows are eliminated before aggregation. Example: WHERE country = 'IN' GROUP BY city HAVING COUNT(*) > 100.
EasyWhich join types does MySQL support, and how do you do a FULL OUTER JOIN?
MySQL supports INNER, LEFT, RIGHT, and CROSS joins but has no FULL OUTER JOIN. Emulate it with a LEFT JOIN UNION a RIGHT JOIN (UNION removes the overlap), or with UNION ALL plus an anti-join (WHERE l.id IS NULL) on the second query to avoid the dedup cost. Interviewers ask this to check you know the limitation, not just join syntax.
EasyWhat is the difference between DELETE, TRUNCATE, and DROP?
DELETE is DML: row-by-row, supports WHERE, is transactional, and fires triggers. TRUNCATE is DDL: it deallocates the table, resets AUTO_INCREMENT, causes an implicit commit so it cannot be rolled back, and skips DELETE triggers. DROP removes the table definition, data, and indexes entirely.
EasyWhat index types does MySQL support?
InnoDB uses B+tree indexes for both the clustered primary key and secondary indexes; MySQL also offers FULLTEXT and SPATIAL indexes, and HASH indexes on the MEMORY engine. MySQL 8 added descending, functional, and invisible indexes. The key structural fact: the clustered index holds the actual row data, and every secondary index stores the primary key as its row pointer.
MediumHow do you read EXPLAIN output — which columns matter most?
Start with type, the access method, ranked roughly const > eq_ref > ref > range > index > ALL, where ALL is a full table scan. Then key and key_len show which index was chosen and how much of a composite index is used, rows × filtered estimates the work, and Extra flags "Using index" (covering), "Using filesort", and "Using temporary". On MySQL 8.0.18+ run EXPLAIN ANALYZE to get actual row counts and timings instead of estimates.
MediumHow does column order in a composite index work, and what is a covering index?
A composite index on (a,b,c) supports the leftmost prefixes — a; a,b; a,b,c — and a range condition on one column stops use of the columns after it, so put equality columns first and the range or sort column last. WHERE b = ? alone cannot seek that index (MySQL 8's skip scan helps only in narrow low-cardinality cases). A covering index contains every column the query needs, so InnoDB answers from the index alone — shown as "Using index" in Extra.
MediumWhat are MySQL's isolation levels, and how does InnoDB prevent phantom reads?
READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ (the default), and SERIALIZABLE. InnoDB's REPEATABLE READ uses MVCC snapshots for consistent reads and next-key locks — record plus gap locks — on locking reads, which is how it prevents phantoms even though the SQL standard does not require it at that level. High-write teams often drop to READ COMMITTED to reduce gap-lock contention and deadlocks.
MediumHow does InnoDB implement ACID, especially durability?
Atomicity comes from undo logs, durability from the redo log flushed at commit (innodb_flush_log_at_trx_commit=1) plus the doublewrite buffer that protects against torn pages, and isolation from MVCC plus locking. When the binlog is enabled, InnoDB runs an internal two-phase commit so the binlog and redo log can never disagree after a crash. That binlog–redo 2PC is a favourite senior-round follow-up.
MediumHow does MySQL replication work?
The source writes changes to the binary log (ROW format is the default and safest); replicas pull it with an IO thread and apply it with SQL applier threads, asynchronously by default. Semi-synchronous replication makes commit wait for at least one replica's acknowledgment, and GTIDs give every transaction a global ID so failover uses SOURCE_AUTO_POSITION instead of binlog file/offset math. Lag is checked with SHOW REPLICA STATUS and reduced with parallel appliers (replica_parallel_workers) and smaller transactions.
MediumHow do you get the top 3 earners per department using MySQL 8 window functions?
Use ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) in a derived table and filter rn <= 3 outside it. Know the difference: ROW_NUMBER() is always unique, RANK() leaves gaps after ties, DENSE_RANK() does not. Window functions need MySQL 8.0+ — on the 5.7 systems still common in services projects, the fallback is a correlated subquery, and saying so signals real-world exposure.
MediumWhen would you use stored procedures, and what are their drawbacks?
Procedures cut network round-trips and centralize logic — Indian BFSI and services codebases run on them, so CREATE PROCEDURE, DELIMITER, IN/OUT parameters, and cursors are fair game. The drawbacks: they are hard to version-control and unit test, they hide business logic from the application, and they scale with the single database server rather than horizontally. In a modern data stack the same transformation belongs in dbt or Spark; arguing both sides is the strong answer.
HardA query is slow even though the column is indexed — why might the optimizer skip the index?
The usual causes: a function or expression wraps the column (DATE(created_at) = ...), implicit type conversion (a string column compared to a number) or a charset/collation mismatch on a join (utf8mb3 vs utf8mb4), a leading-wildcard LIKE '%term', or low selectivity where the optimizer prices a full scan cheaper than millions of secondary-index lookups plus clustered-index hits. Diagnose with EXPLAIN (key is NULL) and refresh stale statistics with ANALYZE TABLE. FORCE INDEX is a last resort — fixing sargability is the real answer.
HardWhy do random UUID primary keys hurt InnoDB, and what do you do instead?
InnoDB stores the table inside the primary-key B+tree and every secondary index stores the PK as its pointer — so a long PK bloats every index, and random UUIDv4 values insert into random pages, causing page splits and buffer-pool churn. Use AUTO_INCREMENT, or store UUIDs with UUID_TO_BIN(uuid, 1), which swaps the timestamp bits so inserts become roughly sequential. This question reliably separates people who have run MySQL at scale from people who have only queried it.
HardHow does partitioning work in MySQL, and when is it the wrong tool?
MySQL supports RANGE, LIST, HASH, and KEY partitioning — typically RANGE on a date column — and the wins are partition pruning on time-bounded queries and instant retention via ALTER TABLE ... DROP PARTITION instead of huge DELETEs. Hard constraints: every unique key including the primary key must contain the partitioning column, and partitioned InnoDB tables cannot have foreign keys. It does not replace good indexing, and when write volume outgrows one server the answer is sharding, not more partitions.
HardWalk me through debugging a slow MySQL query and replication lag in production.
For queries: enable the slow query log with a sensible long_query_time, aggregate with pt-query-digest or the sys schema (sys.statement_analysis, statements_with_full_table_scans), then EXPLAIN ANALYZE the top offenders and fix indexes or rewrite. For lag: SHOW REPLICA STATUS first; the single-threaded applier is the usual bottleneck, so enable replica_parallel_workers with WRITESET dependency tracking, and break up huge transactions like bulk DELETEs that cause lag spikes. Interviewers want the workflow, not a list of tool names.
Related Guides
Keep Preparing
Move between roadmaps, interview questions, and tools without losing your preparation thread.
Is MySQL enough to clear data engineering interviews in India?
It clears the SQL round, which is the hardest filter — strong MySQL depth is what gates 6–12 LPA services roles and the screening rounds at 25 LPA+ product roles alike. Full data engineering loops add warehousing, data modeling, and Spark on top, but a weak database round ends the loop before those matter.
MySQL or PostgreSQL — which should I prepare for interviews?
Prepare one deeply and learn the deltas: indexes, transactions, and EXPLAIN reasoning transfer almost entirely. In Indian JDs, MySQL dominates services companies and older product stacks on RDS/Aurora, while Postgres is increasingly the default at fintech startups and GCCs — pick based on your target list.
How deep do interviewers go into InnoDB internals?
At 2–5 years they expect clustered vs secondary indexes, the buffer pool, redo/undo logs, and isolation levels with locking behaviour. Senior rounds add the binlog–redo two-phase commit, page splits from random primary keys, and why REPEATABLE READ plus next-key locks differs from the SQL standard.
Are stored procedures still asked in 2026?
Yes — BFSI clients and services-company codebases run heavily on them, so CREATE PROCEDURE, DELIMITER, IN/OUT parameters, and cursors are fair game there. Be equally ready to argue why modern pipelines put that logic in dbt or Spark instead; showing both sides is the winning answer.
Next Step
Turn The Guide Into Practice
Use PrepNPlaced tools to turn this learning path into resume proof, targeted practice, and interview-ready explanations.