🐬
Database & Messaging

MySQL

Popular open-source relational database management system

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

MySQL stores structured data (users, orders, posts) that websites and apps read and write.

📁

Config files for MySQL

Where to create or edit the main configuration — paths below match the setup steps.

  • /etc/mysql/my.cnf

    Location: MySQL server

    Server options, bind address, datadir

📥

Step 01

Install MySQL

(01)Install MySQL Server

Linux
1# Ubuntu / Debian
2sudo apt-get update
3sudo apt-get install -y mysql-server
4sudo systemctl enable mysql
5sudo mysql_secure_installation
6
7# RHEL / Fedora
8sudo dnf install -y mysql-server
9sudo systemctl start mysqld

Step 02

Verify

(01)Connect

Linux
1mysql -u root -p
2SELECT VERSION();

Step 03

Manage MySQL

(01)Database operations

Linux
1sudo systemctl start mysql
2sudo systemctl status mysql
3mysql -u root -p -e "SHOW DATABASES;"
4mysqldump -u root -p mydb > backup.sql
5mysql -u root -p mydb < backup.sql
🔧

Step 04

Common Problems

#1Access denied for user 'root'@'localhost'

Linux
1sudo systemctl status mysql
2sudo mysql -u root
3# Or reset password:
4sudo mysql_secure_installation

📋Config templates

2 YAML templates for MySQL. Copy and deploy after setup.

2 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

docker-compose.yaml

PostgreSQL database + Flask app with env file and volume persistence

yaml
1version: "3.9"
2
3services:
4 db:
5 image: postgres:15-alpine
6 environment:
7 POSTGRES_DB: dukaan_db
8 POSTGRES_USER: dukaan
9 POSTGRES_PASSWORD: dukaan123
10 ports:
11 - "5432:5432"
12 volumes:
13 - pgdata:/var/lib/postgresql/data
14
15 app:
16 build: .
17 ports:
18 - "5000:5000"
19 env_file:
20 - .env
21 depends_on:
22 - db
23
24volumes:
25 pgdata:

Dockerfile

Flask application container image

dockerfile
1FROM python:3.12-slim
2WORKDIR /app
3COPY requirements.txt .
4RUN pip install --no-cache-dir -r requirements.txt
5COPY . .
6EXPOSE 5000
7CMD ["python", "app.py"]
📄

Step 01

Run with Docker Compose

(01)Build and start services

Linux
1cd your-project/
2docker compose up -d --build
3docker compose ps
4docker compose logs -f app

(02)Stop and clean up

Linux
1docker compose down
2docker compose down -v # remove volumes