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.
-
Most asked How do you read EXPLAIN output in MySQL?
Look at type (access method, from best const/eq_ref/ref/range to worst ALL = full scan), key (the index chosen), rows (estimated rows examined), filtered, and Extra (Using index, Using where, Using…
-
Most asked What causes deadlocks in MySQL, and how do you handle them?
A deadlock happens when two transactions each hold a lock the other needs. InnoDB detects it and rolls back one transaction (the 'victim') with error 1213. Applications must retry the whole…
-
Most asked How do you deal with replication lag when reading from replicas?
Route reads that must see the user's own recent writes to the primary (read-your-writes), monitor lag, and only use replicas for reads that tolerate staleness. Reduce lag with parallel appliers,…
-
Most asked How should you store money in MySQL?
Use DECIMAL(p, s) (exact decimal arithmetic) or an integer number of minor units (cents). Never use FLOAT or DOUBLE, which are binary approximations: 0.1 + 0.2 is not exactly 0.3.
-
Most asked How do you find the slowest queries in a MySQL server?
Enable the slow query log (long_query_time, optionally log_queries_not_using_indexes) and summarise it with pt-query-digest, or query performance_schema.events_statements_summary_by_digest (and the…
-
Most asked How do you delete or update millions of rows safely in production?
In small batches (for example 1,000 to 10,000 rows) by primary-key ranges, each in its own short transaction, with a pause between batches and monitoring of replication lag. Never in one giant…
-
How would you shard a MySQL database, and what problems does sharding create?
Split data across several MySQL servers by a shard key (usually tenant or user ID), with a routing layer (application code, Vitess, or a proxy) that sends each query to the right shard. Choose the…
-
How do you store and index JSON in MySQL?
Use the JSON type (validated, stored in a binary format with fast key access). To index a JSON field, create a generated column extracting it and index that, use a functional index, or use a…
-
How do you manage users and privileges securely in MySQL?
Give each application its own account with the least privileges it needs (usually SELECT, INSERT, UPDATE, DELETE on its schema), restrict the host it can connect from, use roles (8.0+) to group…
-
How do you route reads to replicas and writes to the primary?
Either in the application (separate read and write connections, as Laravel and Rails support), or in a proxy such as ProxySQL or MySQL Router that inspects queries or ports. Either way you must…
-
How would you plan an upgrade to a newer MySQL major version?
Check the release notes and removed features, run MySQL Shell's upgrade checker, test the application and slow queries against the new version on a copy of production data, then upgrade replicas…
-
How do you choose integer column sizes, and does INT(11) mean anything?
Choose by range: TINYINT (1 byte), SMALLINT (2), INT (4, about +/-2.1 billion or 0 to 4.29 billion unsigned) and BIGINT (8). The number in INT(11) is only a display width, deprecated in 8.0; it does…