Learn 🧠 All Concepts (20) 🤖 What is an LLM? 📚 RAG Explained ⚡ AI Agents 💻 Run AI Locally 🇮🇳 AI in India 📖 Learn Tracks 🔧 DevOps Track ⚙️ AI Ops Track 🗺️ AI Engineer Roadmap
Tools 🔧 AI Tools Directory 🔓 Open Source AI ⭐ Top GitHub Repos ✦ Claude Skill Repos 🚀 Ready-to-Deploy Projects
Build 🏗️ Build Hub 🎯 Master Prompts 🧩 RAG Agents 🚀 App Megaprompts
Workflows ⚡ All Workflows (22) 🎥 Text to Video 🎞️ Image to Video 🔊 Text to Speech ♻️ Automation
Resources 🧪 Colab Notebooks ⚙️ n8n Workflows 📈 Algo Trading 💰 Passive Income
🗂️ Browse All Topics About AItheGuru
Learn MySQL Rahul discovers why databases exist
MySQL Ch 1 / 18 Beginner
🗄️

Rahul discovers why databases exist

What MySQL is, how to install it, and your first working database in one session

⏱ 12 min 6 commands 5 takeaways
🗄️
In this chapter
Rahul
Backend developer, day 1 with databases
The story

Rahul is a backend developer at a Hyderabad startup. He has been writing Python for two years. His company just told him: our new feature needs a database and you are owning it.

He had heard of MySQL. He thought it was complicated. By the end of his first day he had a working database with real data inside it.

WHAT IS A DATABASE AND WHY DO YOU NEED ONE

Imagine your app stores user information. Without a database you store it in a Python dictionary or a JSON file. This works for 10 users. It breaks at 10,000. You cannot search it efficiently. You cannot sort it. Multiple users at the same time corrupt data. You cannot ask "show me all users who signed up last month."

A database solves all of this. MySQL is a database that stores data in tables (like Excel sheets), lets you search and sort millions of rows in milliseconds, handles many users at the same time safely, and keeps your data even if the server crashes.

HOW MYSQL ORGANISES DATA

Think of it like this:

MySQL Server = an office building
Database     = one floor of that building
Table        = one room on that floor
Row          = one file in that room
Column       = one field in every file (name, email, age)

A users table looks like this:

id | name          | email               | city
---+---------------+---------------------+-----------
 1 | Rahul Sharma  | rahul@example.com   | Hyderabad
 2 | Priya Patel   | priya@example.com   | Mumbai
 3 | Arjun Kumar   | arjun@example.com   | Bangalore

INSTALLING MYSQL

# Ubuntu/Debian:
sudo apt update
sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql
sudo mysql_secure_installation   # set root password, remove test data
# Check it is running:
sudo systemctl status mysql
# CentOS/RHEL:
sudo yum install mysql-server -y
sudo systemctl start mysqld
sudo grep 'temporary password' /var/log/mysqld.log

CONNECTING TO MYSQL

sudo mysql                          # as root on Linux (no password)
mysql -u root -p                    # with password prompt
mysql -h 10.0.0.5 -u appuser -p db  # remote server

Once connected you see: mysql>

Every SQL command ends with a semicolon ; -- if you forget it and press Enter, MySQL waits for more. Just type ; and press Enter.

FIRST COMMANDS TO KNOW

SHOW DATABASES;        -- list all databases
USE myapp_db;          -- switch to a database
SHOW TABLES;           -- list tables in current database
DESCRIBE users;        -- show columns of a table
EXIT;                  -- leave MySQL

CREATING YOUR FIRST DATABASE AND TABLE

CREATE DATABASE myapp_db;
USE myapp_db;
CREATE TABLE users (
    id         INT AUTO_INCREMENT PRIMARY KEY,
    name       VARCHAR(100) NOT NULL,
    email      VARCHAR(150) NOT NULL UNIQUE,
    city       VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Column types:

- INT: whole numbers

- VARCHAR(100): text up to 100 characters

- TIMESTAMP: date and time

- AUTO_INCREMENT PRIMARY KEY: MySQL assigns 1, 2, 3 automatically

- NOT NULL: cannot be empty

- UNIQUE: no two rows can have the same value

- DEFAULT CURRENT_TIMESTAMP: fills in current time automatically

INSERT YOUR FIRST DATA

INSERT INTO users (name, email, city) VALUES
    ('Rahul Sharma',  'rahul@example.com',  'Hyderabad'),
    ('Priya Patel',   'priya@example.com',  'Mumbai'),
    ('Arjun Kumar',   'arjun@example.com',  'Bangalore'),
    ('Meera Singh',   'meera@example.com',  'Delhi');
-- Check it worked:
SELECT * FROM users;

Rahul spent 45 minutes doing all of this on day one. He had a working database. The rest is just learning to ask better questions of your data.

Key takeaways

A database organises data in tables (like Excel) — tables have rows (one record each) and columns (fields like name, email, city)

AUTO_INCREMENT PRIMARY KEY automatically assigns unique IDs — never set this manually

Every SQL statement ends with a semicolon — if MySQL keeps waiting, just type ; and press Enter

DESCRIBE tablename shows every column, its type, and constraints — use this constantly when learning a new table

VARCHAR(100) is text up to 100 chars, INT is a whole number, TIMESTAMP is date and time with auto-default support

Commands from this chapter
$ sudo apt install mysql-server -y && sudo mysql_secure_installation
Install MySQL and secure it
$ sudo mysql
Connect to MySQL as root on Linux
$ SHOW DATABASES;
List all databases on this server
$ CREATE DATABASE myapp_db; USE myapp_db;
Create and switch to a database
$ DESCRIBE users;
Show all columns and their types for a table
$ SELECT * FROM users;
Show all rows and columns from a table