How do I install and set up a database for learning SQL?

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:

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:

  1. SELECT, FROM, WHERE — retrieving data
  2. ORDER BY, LIMIT — sorting and paging
  3. JOIN — combining tables (INNER, LEFT, RIGHT)
  4. GROUP BY, aggregate functions (COUNT, SUM, AVG)
  5. Subqueries and CTEs (WITH clauses)
  6. INSERT, UPDATE, DELETE — modifying data
  7. CREATE TABLE, constraints, indexes — schema design

Great Practice Resources

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:

  1. Install MySQL (or run it via Docker)
  2. DBeaver as your client
  3. Import the Sakila sample database
  4. Work through SQLZoo tutorials alongside it

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.