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 19 Oct 2026. 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
How do InnoDB's isolation levels differ, and which one is the default?
Say REPEATABLE READ is the default and that next-key locks are why InnoDB blocks phantoms where the SQL standard allows them. We drop to READ COMMITTED when gap-lock waits and deadlocks pile up under heavy inserts, and only with row-based binlogs. SERIALIZABLE almost never appears in data pipelines, and saying so is a good answer.
Name the default, then say what you would change and why
Behaviour
READ COMMITTED
REPEATABLE READ (default)
SERIALIZABLE
Consistent read snapshot
Fresh snapshot for every statement
One snapshot, taken at the first read
None with autocommit off; every SELECT takes shared locks
Non-repeatable reads
Possible
Prevented by the snapshot
Prevented
Gap locks on locking reads
Off, except duplicate-key and foreign-key checks
On for range scans, which is what blocks phantoms
On for range scans
Binary log format
Logged as rows; binlog_format=STATEMENT errors out
Any
Any
Pick it when
Heavy concurrent inserts and gap-lock deadlocks
Default; keep it unless you can say why not
Rarely; strict correctness over throughput
Why do indexing and EXPLAIN separate candidates?
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
Why do InnoDB, transactions, and replication dominate senior MySQL rounds?
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
MySQL interview questions and answers: the eight that come up most
MySQL rounds in Indian services and product companies mix plain SQL with what MySQL does differently: storage engines, the query cache that no longer exists, EXPLAIN output, and the replication questions that arrive at three years. The answers below are what a good candidate says in under a minute each.
InnoDB vs MyISAM, and why the default changed
What EXPLAIN shows and which column to read first
CHAR vs VARCHAR, and where the bytes go
DELETE, TRUNCATE and DROP on a large table
Why a query ignores the index you built
GROUP BY with ONLY_FULL_GROUP_BY on
InnoDB vs MyISAM
InnoDB has row-level locking, transactions, foreign keys and crash recovery through its redo log; MyISAM has table locks, no transactions and is faster only for read-only tables that are bulk-loaded. InnoDB has been the default since 5.5, and 'we use MyISAM for the logs table' is the follow-up an interviewer wants you to question.
Reading EXPLAIN
Look at type first: ALL means a full table scan, ref or eq_ref means an index was used, range means an index range. Then rows (the estimate the optimizer worked from) and Extra: 'Using filesort' and 'Using temporary' are the two phrases that explain most slow queries.
The index exists, so why the full scan?
Four usual causes: a function wrapped around the column (WHERE YEAR(created_at) = 2026), a leading wildcard (LIKE '%tata'), a type mismatch (a numeric id compared with a string), or a composite index whose first column is not in the WHERE clause. Rewrite the predicate to a range and the index comes back.
CHAR vs VARCHAR
CHAR(10) always stores ten characters, padded; VARCHAR(10) stores the length plus the characters. CHAR suits fixed codes (a two-letter state), VARCHAR suits names. The interviewer is checking you know the padding is real, not a display setting.
DELETE, TRUNCATE, DROP
DELETE removes rows one by one, is logged and can be rolled back inside a transaction, and leaves the auto-increment counter where it was. TRUNCATE drops and recreates the table, is fast, resets the counter and cannot be rolled back in MySQL. DROP removes the table and its definition.
Second highest salary in MySQL
SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees), or with a window function on 8.0: DENSE_RANK() OVER (ORDER BY salary DESC) and pick rank 2. Say that the first form returns NULL when only one salary exists, and why the window version handles ties.
ONLY_FULL_GROUP_BY rejected my query
MySQL 5.7 and later refuse a SELECT column that is neither in GROUP BY nor aggregated, because the value would be picked arbitrarily. Either add it to GROUP BY, aggregate it (MAX, ANY_VALUE), or restructure with a join to the grouped result.
How does replication work, and what lags?
The primary writes changes to its binary log; a replica's I/O thread copies them to a relay log and its SQL thread applies them. Lag appears when a long transaction or a single-threaded apply falls behind; SHOW REPLICA STATUS shows Seconds_Behind_Source. Reads that must see their own writes go to the primary.
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. Every answer is open; collapse any you have already covered.
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.
By company
Data Analyst interviews that ask these questions
See how this topic shows up in real Data Analyst loops — rounds, difficulty and company-specific questions:
Is MySQL enough to clear data engineering interviews in India?
It clears the SQL round, which is the hardest filter: strong MySQL depth gates the screening rounds at services companies and product companies 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.
What is the difference between SQL and MySQL?
SQL is a language; MySQL is a database system that runs it. You write SQL to define, query and change data, and MySQL is one of the programs that stores the data and executes that SQL, alongside PostgreSQL, SQL Server and Oracle. Each adds its own functions and syntax on top of standard SQL, so most of what you learn on one transfers to the others.
Next Step
Turn The Guide Into Practice
Use PrepNPlaced tools to turn this learning path into resume proof, targeted practice, and interview-ready explanations.