✅ Top 25 MySQL Interview Questions and Answers (2025)
Introduction:
Are you preparing for a MySQL interview? Whether you’re aiming to become a backend developer, data analyst, or database administrator, MySQL is one of the most essential skills employers look for. It’s widely used in web development, WordPress, and enterprise applications. Mastering MySQL can open doors to high-paying job opportunities. In this article, we’ve curated the top 25 most commonly asked MySQL interview questions with clear, concise answers to help you ace your interview. These questions cover both basic and intermediate levels—ranging from SQL syntax, joins, indexes, data types, to performance tuning. Read till the end and bookmark this guide for your revision!
1. What is MySQL?
MySQL is an open-source relational database management system (RDBMS) that uses SQL (Structured Query Language) for accessing and managing data.
2. What is the difference between SQL and MySQL?
SQL is a language for managing relational databases, while MySQL is an RDBMS that implements SQL to store and retrieve data.
3. What are the main data types in MySQL?
Numeric: INT, FLOAT, DOUBLE, DECIMAL
Date/Time: DATE, DATETIME, TIMESTAMP
String: VARCHAR, TEXT, CHAR, ENUM, BLOB
4. What is a Primary Key?
A primary key uniquely identifies each row in a table. It must be unique and cannot contain NULL values.
5. What is a Foreign Key?
A foreign key in one table points to the primary key in another table, ensuring referential integrity.
6. Difference between WHERE and HAVING?
WHERE filters rows before aggregation; HAVING filters after aggregation.
7. How do you find duplicates in a MySQL table?
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;
8. Difference between CHAR and VARCHAR?
CHAR is fixed-length; VARCHAR is variable-length. CHAR pads unused space, VARCHAR does not.
9. What is Normalization?
Normalization organizes data to minimize redundancy. Forms include 1NF, 2NF, 3NF, etc.
10. Types of JOINs in MySQL?
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN (via UNION)
- CROSS JOIN
- SELF JOIN
11. What is MySQL’s default port?
3306
12. How to create a user and grant privileges?
CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost';
13. How to get current date/time in MySQL?
SELECT NOW(); -- Date & Time
SELECT CURDATE(); -- Date only
SELECT CURTIME(); -- Time only
14. DELETE vs TRUNCATE vs DROP?
DELETE: Removes specific rows, can be rolled back.
TRUNCATE: Removes all rows, faster, can’t be rolled back.
DROP: Deletes entire table structure and data.
15. What is an Index in MySQL?
An index improves query speed. Types: PRIMARY, UNIQUE, FULLTEXT, SPATIAL.
16. How to perform case-insensitive search?
SELECT * FROM users WHERE LOWER(name) = 'john';
17. What is a Subquery?
A subquery is a query inside another SQL query. It can be used in SELECT, WHERE, or FROM clauses.
18. What does GROUP BY do?
It groups rows with the same values and is used with aggregate functions like COUNT, AVG, SUM.
19. How to check MySQL version?
SELECT VERSION();
20. What is AUTO_INCREMENT?
It auto-generates a unique number for a new record, typically used with primary keys.
21. Use of IN and BETWEEN in MySQL?
SELECT * FROM users WHERE age IN (25, 30, 35);
SELECT * FROM users WHERE age BETWEEN 18 AND 30;
22. How to prevent SQL Injection?
Use prepared statements, input sanitization, and avoid dynamic SQL in user input areas.
23. What is a View?
A virtual table created using a SELECT query. It simplifies complex queries and enhances security.
24. How to optimize a slow MySQL query?
- Use indexes
- Analyze with EXPLAIN
- Avoid SELECT *
- Limit result rows
- Optimize joins
25. What is Full-Text Search?
SELECT * FROM articles
WHERE MATCH(title, content)
AGAINST ('+mysql +indexing' IN BOOLEAN MODE);
Conclusion: These questions are great for brushing up on MySQL fundamentals before interviews. Keep practicing and stay confident. Want a downloadable PDF version? Let us know in the comments!