Getting a local database up and running is the first step toward learning SQL hands-on. Here’s a practical, beginner-friendly guide.
Step 1: Choose a Database System
For learning SQL, I recommend one of these free options:
| Database | Best For |
|---|---|
| SQLite | Absolute beginners, no setup |
| MySQL | Web development, widely used |
| PostgreSQL | Modern SQL features, professional use |
| H2 | Java developers, embedded testing |
Step 2: Install the Database
Option A: MySQL (Recommended for Beginners)
Windows / macOS:
1. Download the MySQL Community Server from dev.mysql.com/downloads
2. Run the installer and choose “Developer Default”
3. During setup, set a root password (remember it!)
4. Accept default port 3306
macOS (via Homebrew):
brew install mysql
brew services start mysql
mysql_secure_installation
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql
sudo mysql_secure_installation
Option B: PostgreSQL
Windows / macOS: Download from postgresql.org/download
macOS:
brew install postgresql@16
brew services start postgresql@16
Linux:
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
Option C: Docker (Cleanest Setup)
If you have Docker, this is the fastest way:
# MySQL
docker run --name mysql-learn -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql:8
# PostgreSQL
docker run --name pg-learn -e POSTGRES_PASSWORD=root -p 5432:5432 -d postgres:16
Step 3: Install a Database Client
You’ll want a GUI to browse tables and run queries visually:
- DataGrip (JetBrains, paid but excellent) — or use the Database tool window built into IntelliJ IDEA Ultimate
- DBeaver (free, universal) — dbeaver.io
- MySQL Workbench (free, MySQL-specific)
- pgAdmin (free, PostgreSQL-specific)
Step 4: Create Your First Database
Connect to your server via CLI or GUI and run:
CREATE DATABASE learning_sql;
USE learning_sql; -- MySQL syntax
-- \c learning_sql -- PostgreSQL syntax
Step 5: Load Sample Data
Learning SQL is much easier with realistic data. Try one of these well-known sample databases:
- Sakila (MySQL) — DVD rental store: dev.mysql.com/doc/sakila
- Chinook — Digital music store, works on all major DBs: github.com/lerocha/chinook-database
- Northwind — Classic Microsoft sample, ported to many DBs
- DVD Rental (PostgreSQL) — neon.tech/postgresql/postgresql-getting-started
Import via CLI, for example:
mysql -u root -p learning_sql < sakila-schema.sql
mysql -u root -p learning_sql < sakila-data.sql
Step 6: Practice SQL Basics
Start with these fundamentals in order:
SELECT,FROM,WHERE— retrieving dataORDER BY,LIMIT— sorting and pagingJOIN— combining tables (INNER, LEFT, RIGHT)GROUP BY, aggregate functions (COUNT,SUM,AVG)- Subqueries and CTEs (
WITHclauses) INSERT,UPDATE,DELETE— modifying dataCREATE TABLE, constraints, indexes — schema design
Great Practice Resources
- SQLZoo — sqlzoo.net (interactive tutorials)
- LeetCode Database — leetcode.com/problemset/database
- HackerRank SQL — hackerrank.com/domains/sql
- Mode SQL Tutorial — mode.com/sql-tutorial
Step 7: Verify Your Setup
Run a quick sanity check in your SQL client:
SELECT VERSION();
SHOW DATABASES; -- MySQL
-- \l -- PostgreSQL
If you see version info and your learning_sql database listed, you’re all set!
Quick Recommendation
If you want the fastest path with minimal friction:
- Install MySQL (or run it via Docker)
- DBeaver as your client
- Import the Sakila sample database
- Work through SQLZoo tutorials alongside it
