MySQL Interview Questions and Answers: Basic Level

MySQL 45 min min read Updated: Nov 27, 2026 Beginner
MySQL Interview Questions and Answers: Basic Level
Beginner Topic 1 of 3

How to Use This Page

Say each answer aloud in your own words before reading ours. Interviewers like short answers with a tiny example. Facts here refer to MySQL 8.0.

Q1. What is MySQL and how is it different from SQL?

SQL is the language. MySQL is a database server (owned by Oracle, open source with a commercial edition) that understands SQL and stores data in tables. Other servers that speak SQL are PostgreSQL, SQL Server and Oracle Database.

Q2. What are storage engines? Which one is the default?

A storage engine decides how a table is stored and which features it has. InnoDB is the default since MySQL 5.5: it supports transactions, row-level locking and foreign keys. MyISAM (older) has none of these. MEMORY keeps data in RAM only.

Q3. InnoDB vs MyISAM?

InnoDB: transactions, foreign keys, crash recovery, row locks. MyISAM: table locks, no transactions, no crash safety. Use InnoDB for nearly everything today.

Q4. What is the difference between CHAR and VARCHAR?

CHAR(n) is fixed length and padded with spaces (good for codes such as 'IN'). VARCHAR(n) stores only the characters used plus a length byte, so it suits names and emails.

Q5. What is the difference between DATETIME and TIMESTAMP?

DATETIME stores the date and time you give it, with no time zone conversion. TIMESTAMP is stored in UTC and shown in the session time zone. TIMESTAMP covers only 1970 to January 2038 (UTC), while DATETIME covers the years 1000 to 9999.

Q6. What is a primary key? Can it be NULL?

A column (or combination) that uniquely identifies each row. It cannot be NULL and cannot repeat. InnoDB stores the table in primary-key order, so keep it short.

Q7. What is a foreign key and what are its actions?

A column that must match a value in another table's key. ON DELETE and ON UPDATE can be RESTRICT (default), CASCADE, SET NULL or NO ACTION. InnoDB supports SET NULL and CASCADE, not SET DEFAULT.

Q8. How does AUTO_INCREMENT work?

MySQL gives the next number to a column when you do not supply a value. Numbers are never reused after a delete or rollback, so gaps are normal. LAST_INSERT_ID() returns the last id created by the current connection.

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

DELETE removes chosen rows, can have WHERE and can be rolled back inside a transaction. TRUNCATE empties the table quickly, resets AUTO_INCREMENT and commits at once. DROP removes the whole table with its structure.

Q10. What is the difference between WHERE and HAVING?

WHERE filters rows before grouping and cannot use aggregates. HAVING filters groups after GROUP BY.

Q11. What types of joins does MySQL support?

INNER, LEFT, RIGHT, CROSS and self joins. There is no FULL OUTER JOIN: combine LEFT JOIN and RIGHT JOIN with UNION.

Q12. How do you find duplicate rows?

Group by the columns that should be unique and keep groups with a count above one: SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1;.

Q13. What is NULL? How do you compare with it?

NULL means unknown or missing. col = NULL is never true; use IS NULL or the null-safe operator <=>. COALESCE(a, b) and IFNULL(a, b) replace NULL with a default.

Q14. What is the difference between UNION and UNION ALL?

UNION removes duplicate rows, UNION ALL keeps them and is faster.

Q15. What is an index and what does it cost?

A sorted structure that lets MySQL find rows without scanning the table. It speeds up WHERE, JOIN and ORDER BY, but takes disk space and slows INSERT, UPDATE and DELETE.

Q16. What is the difference between a primary key and a UNIQUE key?

Both prevent duplicates. A table has one primary key and it cannot be NULL. A table can have many unique keys, and they allow NULL values (several).

Q17. What character set should you use?

utf8mb4 (the default in 8.0) stores all Unicode, including emoji. The old utf8 in MySQL is really utf8mb3 and cannot store 4-byte characters.

Q18. What are the SQL commands groups?

DDL (CREATE, ALTER, DROP), DML (INSERT, UPDATE, DELETE), DQL (SELECT), DCL (GRANT, REVOKE) and TCL (COMMIT, ROLLBACK, SAVEPOINT).

Q19. What is the difference between LIMIT and OFFSET?

LIMIT n returns at most n rows, OFFSET m skips m rows first. They are used for pagination but get slow with a large offset (see keyset pagination).

Q20. How do you see the structure of a table?

DESCRIBE t; or SHOW COLUMNS FROM t; for columns, SHOW CREATE TABLE t; for the full definition including indexes and keys, and SHOW INDEX FROM t; for indexes.

Quick Demo for Two of the Answers

sql CREATE TABLE t (id INT AUTO_INCREMENT PRIMARY KEY, v VARCHAR(5)); INSERT INTO t (v) VALUES ('a'), ('b'), ('c'); DELETE FROM t WHERE id = 3; INSERT INTO t (v) VALUES ('d'); SELECT id, v FROM t ORDER BY id;

Result:

idv
1a
2b
4d

The new row got id 4: the deleted id 3 was not reused.

sql SELECT NULL = NULL AS equal_op, NULL <=> NULL AS null_safe_equal, 1 <=> 1 AS one_vs_one;

Result:

equal_opnull_safe_equalone_vs_one
NULL11

Conclusion

Know engines (InnoDB), data types, keys, joins (no FULL JOIN), delete options, NULL handling and utf8mb4. Give a short definition, then a tiny example.

Quick Summary: InnoDB, CHAR vs VARCHAR, keys, AUTO_INCREMENT, DELETE vs TRUNCATE, NULL, utf8mb4.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators