MySQL interview questions, and how to answer them out loud

2026-12-06来源 dev.toEnglish

Originally published on four-leaf.ai.

Key takeaways

A MySQL interview asks you to write SQL that runs in MySQL's dialect and then explain what the engine does with it. Expect questions on InnoDB, how its clustered index works, how to read EXPLAIN, and which isolation level you're running under. You can write a correct query and still lose the round, because the interviewer's next question is often why MySQL ran it that way.

  1. Ask the recruiter which database the editor runs and which version, because a query written from PostgreSQL habit can fail to run, and a screen graded by test cases fails every test when that happens.
  2. Learn how InnoDB stores a table around its primary key, since most index and performance questions follow from that one idea.
  3. Practice reading EXPLAIN output out loud, column by column, on a query you wrote yourself.
  4. Be able to say what the default isolation level is and what it prevents, then what it costs.
  5. Rehearse the answers spoken, not just typed, because the interviewer will push on the second sentence of each one.

MySQL is still a common place to land. In the Stack Overflow 2025 Developer Survey, 40.5% of the developers who answered the database question said they'd done extensive development work in MySQL over the past year, behind PostgreSQL at 55.6%. That gap matters for prep, because plenty of candidates walk into a MySQL round with PostgreSQL reflexes.

Which MySQL questions come up most often?

Part of a MySQL round is query writing: joins, aggregation, window functions, deduplication and date handling, usually against a small schema the interviewer describes. Our SQL interview guide covers how that part gets scored, and the advice carries over. Clarify the question before you type, and check what your join does to rows with no match.

The rest is about the engine, and that's what makes a round a MySQL round rather than a generic SQL one. The common prompts are:

  • What's the difference between InnoDB and MyISAM?
  • How does a clustered index work, and what does a secondary index store?
  • Why isn't this query using my index?
  • Walk me through this EXPLAIN output.
  • What isolation level does InnoDB use by default, and what is a phantom read?
  • How does MySQL handle a deadlock?

We'd expect a data analyst round to lean on the queries and a backend, data engineering or database administrator loop to spend longer on the engine, but loops vary, so ask the recruiter. If you can't find out, prepare both.

How do you answer InnoDB versus MyISAM?

Start with the fact, then give the reason it matters. InnoDB is the default storage engine, and the MySQL 8.4 reference manual labels it "The default storage engine in MySQL 8.4." The manual's feature table lists the differences interviewers want to hear. MyISAM locks at table level and InnoDB at row level, and InnoDB supports transactions and foreign keys where MyISAM supports neither.

Then say what that means for a real application. If two users write to the same MyISAM table at once, one waits for the other's whole table lock, so a busy write path queues up. InnoDB lets them write different rows concurrently, rolls back a failed transaction cleanly, and enforces foreign keys so an order can't point at a customer who doesn't exist.

If you've ever converted a MyISAM table to InnoDB, mention it and say what changed afterwards.

How do you explain indexes in a MySQL interview?

Explain the clustered index first, because every other index answer leans on it. Per the InnoDB index documentation, each InnoDB table stores its rows in a clustered index, which is normally the primary key. With no primary key, InnoDB uses the first UNIQUE index with all key columns defined as NOT NULL, and with neither it builds a hidden one called GEN_CLUST_INDEX.

The follow-up is usually about secondary indexes. In InnoDB, each record in a secondary index contains the primary key columns for the row, so a lookup through a secondary index finds the primary key and then goes back to the clustered index for the rest of the row. That's why a long primary key makes every secondary index bigger, and interviewers like candidates who connect the two without being prompted.

The other classic is the composite index. The MySQL manual on multiple-column indexes says an index can hold up to 16 columns, and it can only be used for lookups on a leftmost prefix. With an index on (col1, col2, col3), a query filtering on col1, or on col1 and col2, can use it, but one filtering only on col2, or on col2 and col3, generally can't. When an interviewer asks why a composite index is ignored, the column order is the first thing to check.

How do you read EXPLAIN output out loud?

Read it one row per table, and say what each row tells you before you say what you'd change. The MySQL EXPLAIN documentation describes the type column as how the table is joined, and the value to watch for is ALL, where "A full table scan is done for each combination of rows from the previous tables." On a big table, that's often where the time goes.

Next, look at key to see which index the optimizer actually picked, and rows for how many rows it expects to examine. Then read Extra. "Using index" means the answer came using only information in the index tree without having to do an additional seek to read the actual row, which is what people mean by a covering index.

Talk through it in that order. Something like "it's scanning the whole orders table, there's no usable key, and it expects to read most of the rows, so I'd add an index on customer_id, created_at because the filter and the sort both use those columns." If you aren't sure the index would help, say you'd add it and run EXPLAIN again, since that's what you'd do at work.

What do transaction and locking questions test?

They test whether you know what the default protects you from. The InnoDB isolation level documentation is direct about it: "The default isolation level for InnoDB is REPEATABLE READ." Under it, consistent reads within the same transaction read the snapshot established by the first read, so a report you run twice inside one transaction gives the same answer.

The usual follow-up is phantom rows. The MySQL manual on phantom rows says the phantom problem occurs within a transaction when the same query produces different sets of rows at different times. Per the InnoDB locking documentation, a next-key lock combines a record lock on the index record and a gap lock on the gap before the index record. InnoDB uses next-key locks for searches and index scans, which prevents phantom rows, so a range you locked can't gain new rows mid-transaction. The cost is that those gap locks block inserts other sessions want to make, which is how a range update ends up stalling traffic.

Deadlocks come next. Per the InnoDB deadlock documentation, when detection is on, InnoDB detects the cycle and rolls back one of the transactions (the victim). The answer interviewers want after that is what your application does about it, which is to retry the rolled-back transaction and keep the lock order consistent across code paths so it happens less.

Why do queries written for PostgreSQL fail in MySQL?

They fail because the two dialects disagree on small things, and a screen graded by test cases won't forgive any of them. The most surprising one is the || operator. In PostgreSQL it joins strings, but the MySQL server SQL modes page shows MySQL treats it as a synonym for OR unless the PIPES_AS_CONCAT mode is set, so in MySQL you should reach for CONCAT() instead. A query that joins strings with || won't error in a SELECT. It'll just return the wrong thing.

Date functions differ too. PostgreSQL candidates reach for DATE_TRUNC, which MySQL doesn't have, so know the MySQL functions you'd use instead, such as DATE_FORMAT, DATEDIFF and DATE_SUB. You don't need every function, but looking up four or five mid-screen burns minutes.

Grouping catches people with older MySQL habits. Per the MySQL GROUP BY documentation, ONLY_FULL_GROUP_BY is on by default, so MySQL rejects a query that selects a column that's neither grouped nor functionally dependent on the grouped columns. PostgreSQL already works that way, but if you learned on an older MySQL install, or one with the mode switched off, those queries used to run. If you know every row in a group has the same value, wrap the column in ANY_VALUE() rather than asking to change the server mode. The same SQL modes page lists strict mode and ERROR_FOR_DIVISION_BY_ZERO among the defaults too, so habits from a loosely configured server may not hold. The simplest fix for all of this is the first action in the list above: ask which engine and version before the day.

How should you practice before a MySQL interview?

Practice the same way you'll be tested, which means writing queries in a real MySQL instance and then explaining them aloud. Spin up MySQL locally, load a small schema with a few thousand rows, and write a query that should use an index. Run EXPLAIN on it, drop the index, run it again and describe the difference as if someone were listening.

The spoken half is where most prep falls short, because reading about next-key locks and explaining them under a follow-up question are different skills. Four-Leaf's AI mock interviews let you set up a Custom round with a name you choose, such as "MySQL internals," and get interview questions built around that topic. After you answer, it can ask a follow-up aimed at the biggest gap in what you said.

If your loop also includes a design round, our system design interview questions post covers how those answers get scored, and our data structures interview questions guide covers the coding round.

Where this is heading

We expect more database rounds to run against a live engine with graded test cases, which makes the dialect question practical rather than academic. The engine questions probably won't go away either, because they're the quickest way for an interviewer to tell someone who has tuned a slow query from someone who has only read about it.

So prepare the explanation alongside the query. Before your interview, pick one slow query from a project you've worked on, run EXPLAIN on it, and be ready to tell the story of what it showed and what you changed.

About Four-Leaf

Four-Leaf is the all-in-one AI job search assistant covering every stage from application to signed offer: voice mock interviews across 25 roles, resume tailoring, cover letters, salary negotiation, email drafting, AI job search, and LinkedIn optimization. 3-day free trial, no credit card. Pricing: $20/mo or $5 / 5 Day Pass.

原文:https://www.a8q9.cn/en/article/mysql-interview-questions-and-how-to-answer-them-out-loud-206a17.html

相关文章