MySQL Interview Questions for 5 Years Experience | Top Q&A with Answers

MySQL Interview Questions for 5 Years Experience (With Answers)

If you have around 5 years of experience in MySQL, interviewers expect strong knowledge of query optimization, indexing, transactions, joins, replication, and real-world database design. Below are the most frequently asked MySQL interview questions with answers for mid-level professionals.


1. What is MySQL and why is it used?

Answer:
MySQL is an open-source relational database management system (RDBMS) used to store and manage structured data using SQL (Structured Query Language). It is widely used because it is fast, reliable, scalable, and supports large applications.


2. What are indexes in MySQL?

Answer:
Indexes are database objects that improve the speed of data retrieval operations.

Types:

  • Primary Index
  • Unique Index
  • Composite Index
  • Full-text Index

👉 Indexes speed up SELECT queries but slow down INSERT/UPDATE/DELETE operations.


3. Difference between InnoDB and MyISAM?

FeatureInnoDBMyISAM
TransactionsSupportedNot supported
Foreign KeysSupportedNot supported
LockingRow-levelTable-level
Crash recoveryYesNo

👉 InnoDB is preferred in modern applications.


4. What are JOINs in MySQL?

Answer:
JOINs are used to combine rows from two or more tables.

Types:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL JOIN (simulated in MySQL)

5. What is normalization?

Answer:
Normalization is the process of organizing data to reduce redundancy and improve data integrity.

Forms:

  • 1NF (Atomic values)
  • 2NF (No partial dependency)
  • 3NF (No transitive dependency)

6. What is denormalization?

Answer:
Denormalization is the process of combining tables to improve read performance at the cost of redundancy.

👉 Used in reporting systems and data warehouses.


7. What are transactions in MySQL?

Answer:
A transaction is a group of SQL operations that execute as a single unit.

Properties (ACID):

  • Atomicity
  • Consistency
  • Isolation
  • Durability

Commands:

  • START TRANSACTION
  • COMMIT
  • ROLLBACK

8. What is a primary key vs foreign key?

Primary KeyForeign Key
Uniquely identifies a rowLinks two tables
Cannot be NULLCan be NULL
One per tableMultiple allowed

9. What is query optimization?

Answer:
Query optimization improves SQL performance using:

  • Proper indexing
  • Avoiding SELECT *
  • Using EXPLAIN plan
  • Avoiding subqueries when possible
  • Using joins efficiently

10. What is EXPLAIN in MySQL?

Answer:
EXPLAIN is used to analyze how MySQL executes a query.

It shows:

  • Table scan type
  • Index usage
  • Number of rows scanned
  • Execution order

11. What is a stored procedure?

Answer:
A stored procedure is a precompiled SQL block stored in the database.

Benefits:

  • Better performance
  • Code reuse
  • Security improvement

12. What are triggers?

Answer:
Triggers are SQL statements that automatically execute before or after INSERT, UPDATE, or DELETE events.

Types:

  • BEFORE trigger
  • AFTER trigger

13. What is replication in MySQL?

Answer:
Replication is the process of copying data from one MySQL server (master) to another (slave).

Types:

  • Master-Slave replication
  • Master-Master replication

Used for:

  • Backup
  • Load balancing
  • High availability

14. How do you handle slow queries?

Answer:

  • Use indexing
  • Optimize joins
  • Use EXPLAIN
  • Avoid unnecessary columns
  • Partition large tables
  • Cache frequent queries

15. What are ACID properties?

Answer:

  • Atomicity → All or nothing
  • Consistency → Data remains valid
  • Isolation → Transactions don’t interfere
  • Durability → Data persists after commit

16. What is a subquery?

Answer:
A query inside another query.

Example use:

  • Filtering results
  • Derived tables
  • Complex conditions

17. Difference between DELETE, TRUNCATE, and DROP?

CommandPurpose
DELETERemoves specific rows
TRUNCATERemoves all rows quickly
DROPDeletes table structure

18. What is partitioning in MySQL?

Answer:
Partitioning divides large tables into smaller parts for better performance.

Types:

  • Range partitioning
  • List partitioning
  • Hash partitioning

19. What is the difference between CHAR and VARCHAR?

CHARVARCHAR
Fixed lengthVariable length
FasterSpace efficient
Uses paddingNo padding

20. How do you improve database performance?

Answer:

  • Proper indexing
  • Query optimization
  • Partitioning large tables
  • Avoiding redundant joins
  • Using caching systems (Redis)
  • Normalized + selective denormalization