For beginners
Database, table, index, transaction — explained in plain English
What is a relational database, really?
Mental model:
| Concept | Like... |
|---|---|
| Database | An Excel file |
| Table | A Sheet in that file |
| Row | A row in the sheet |
| Column | A typed column in the sheet |
| Primary key | The row's unique ID |
| Index | A lookup table for fast queries |
| Transaction | A group of changes that all happen or none do |
MariaDB stores those "files", lets many programs read/write at once safely, survives power loss, and is queried with SQL.
Your first table
CREATE DATABASE blog;
USE blog;
CREATE TABLE posts (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200) NOT NULL,
body TEXT,
author VARCHAR(64) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_author (author)
);
INSERT INTO posts (title, body, author)
VALUES ('Hello', 'First post', 'alice'),
('Another', 'Written by AI', 'bob');
SELECT * FROM posts WHERE author = 'alice';Top beginner pitfalls
- Use
utf8mb4, neverutf8. The legacyutf8only stores 3 bytes/char — no emoji, no rare Han glyphs. - Primary keys:
BIGINT AUTO_INCREMENTor UUID v7. Don't use business fields (email, phone) — they change. - Don't index every column. Indexes speed reads but slow writes and take space.
- Don't forget
COMMITin transactions. - Don't use MyISAM. No transactions, not crash-safe. Default to InnoDB.