Skip to main content

Command Palette

Search for a command to run...

9. ๐Ÿ›ข๏ธ MySQL Basics for DevOps Engineers (Production & Interview Guide)

Published
โ€ข3 min readโ€ขView as Markdown
N

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

TermMeaning
DatabaseCollection of tables
TableStructured data
RowRecord
ColumnField

๐Ÿ”น 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

WHEREHAVING
Before groupingAfter grouping
Filters rowsFilters 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

More from this blog

Beginner to Advanced

16 posts