These questions are frequently asked in senior backend developer and system design interviews. They focus on database performance, scalability, and internal MySQL architecture.
1. What is the difference between MyISAM and InnoDB?
| Feature | InnoDB | MyISAM |
|---|---|---|
| Transactions | Supported | Not supported |
| Row Locking | Yes | No |
| Foreign Keys | Supported | Not supported |
2. What is a clustered index?
A clustered index determines the physical order of rows in a table. In MySQL InnoDB, the primary key acts as the clustered index.
---
3. What is the difference between DELETE, TRUNCATE, and DROP?
| Command | Description |
|---|---|
| DELETE | Removes specific rows |
| TRUNCATE | Deletes all rows quickly |
| DROP | Removes table structure and data |
4. What is a composite index?
A composite index is an index on multiple columns. Example:
---
CREATE INDEX idx_user_name_email ON users(name,email);
5. What is database normalization?
Normalization organizes tables to reduce redundancy.
---
- 1NF – Atomic columns
- 2NF – Remove partial dependency
- 3NF – Remove transitive dependency
6. What is the difference between WHERE and HAVING?
WHERE filters rows before grouping. HAVING filters aggregated results. Example:
---
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5;
7. What is an index and why is it used?
Indexes improve query performance by allowing the database engine to locate rows faster instead of scanning the entire table.
---
8. What is the difference between INNER JOIN and LEFT JOIN?
| Join Type | Description |
|---|---|
| INNER JOIN | Returns matching rows only |
| LEFT JOIN | Returns all rows from left table |
9. What is ACID in MySQL?
ACID properties guarantee transaction reliability:
---
- Atomicity
- Consistency
- Isolation
- Durability
10. What is EXPLAIN in MySQL?
EXPLAIN shows how MySQL executes a query. Example:
---
EXPLAIN SELECT * FROM users WHERE email='user@email.com';It helps identify slow queries.
11. What is a deadlock?
A deadlock occurs when two transactions wait for each other to release locks. MySQL detects and resolves deadlocks automatically.
---
12. What is a foreign key?
A foreign key creates a relationship between two tables.
---
FOREIGN KEY (customer_id) REFERENCES customers(id);
13. What is query optimization?
Query optimization improves query performance using indexes, optimized joins, and efficient query plans.
---
14. What is a view?
A view is a virtual table created from a query.
---
CREATE VIEW active_users AS SELECT id, name FROM users WHERE status='ACTIVE';
15. What is a stored procedure?
A stored procedure is a reusable SQL program stored in the database.
---
CREATE PROCEDURE getUsers() BEGIN SELECT * FROM users; END;
16. What is replication in MySQL?
Replication copies data from a primary database to replica databases to improve availability and read scalability.
---
17. What is sharding?
Sharding distributes data across multiple databases to handle large datasets and high traffic.
---
18. What causes slow queries?
Common causes:
---
- Missing indexes
- Large table scans
- Unoptimized joins
19. What is a covering index?
A covering index contains all the columns needed by a query, eliminating the need to read the table.
---
20. How do you optimize a slow MySQL query?
Steps:
- Use EXPLAIN
- Add proper indexes
- Avoid SELECT *
- Optimize joins
- Limit returned rows
0 comments