9. ๐ข๏ธ MySQL Basics for DevOps Engineers (Production & Interview Guide)
Open to Work | Cloud & DevOps Engineer | AWS | Kubernetes | Terraform | CI/CD | Automations | Available for Full-Time / Freelance / Mentorship
๐ฏ Why DevOps Engineers Must Know MySQL
As a DevOps engineer, you may not design schemas, but you must:
Monitor database health
Troubleshoot performance issues
Handle backups & recovery
Support application teams
๐น What is MySQL?
MySQL is an open-source relational database that stores data in tables (rows & columns).
Used in:
Web applications
Microservices
Cloud-native apps
๐น Basic MySQL Concepts
| Term | Meaning |
| Database | Collection of tables |
| Table | Structured data |
| Row | Record |
| Column | Field |
๐น Connect to MySQL
mysql -u root -p
๐น List Databases & Tables
SHOW DATABASES;
USE mydb;
SHOW TABLES;
๐น Fetch All Records
SELECT * FROM employees;
๐น WHERE Clause
SELECT * FROM employees WHERE dept = 'IT';
๐น GROUP BY (Interview Favorite)
SELECT dept, COUNT(*) FROM employees GROUP BY dept;
Used for aggregation.
๐น WHERE vs HAVING
| WHERE | HAVING |
| Before grouping | After grouping |
| Filters rows | Filters groups |
SELECT dept, COUNT(*)
FROM employees
GROUP BY dept
HAVING COUNT(*) > 5;
๐น Indexes (Performance Basics)
Indexes improve read performance.
CREATE INDEX idx_email ON users(email);
โ ๏ธ Too many indexes slow writes.
๐น MySQL Users & Permissions
CREATE USER 'appuser'@'%' IDENTIFIED BY 'password';
GRANT SELECT, INSERT ON mydb.* TO 'appuser'@'%';
FLUSH PRIVILEGES;
๐น Backup MySQL Database
mysqldump -u root -p mydb > mydb.sql
๐น Restore Database
mysql -u root -p mydb < mydb.sql
๐น Check Running Queries
SHOW PROCESSLIST;
Used when:
DB is slow
Queries are stuck
๐น Monitor MySQL (DevOps View)
CPU & memory usage
Disk I/O
Slow queries
Connection count
๐น MySQL in Docker (Common Setup)
docker run -d \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=mydb_password \
-p 3306:3306 mysql
๐น MySQL on Kubernetes (Basic Idea)
StatefulSet
Persistent Volumes
Secrets for credentials
๐น Common Production Issues
Database Slow
Missing indexes
Long-running queries
High connections
Database Down
Disk full
Memory exhaustion
Corrupt tables
๐น Real Production Scenario
Issue: Application latency high
Cause: Full table scan
Fix: Added index on search column
Result: Query time reduced drastically
๐ฏ Interview Takeaways
DevOps handles DB operations
GROUP BY & HAVING are common
Backup & restore are critical
Indexes improve performance