Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 4/ 160
01. SQL Foundations & Relational Concepts

Installing PostgreSQL / MySQL & Database Clients (DBeaver, pgAdmin)

Install a local engine, connect with a GUI client, and run your first query safely.

BeginnerLocal Install · Connection Strings3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Install the database, install a program that talks to it, and connect them with an address and a password.

Think of it like…

The database server is the library and the client is your library card plus the catalogue terminal: the books live in the library, and the terminal is how you ask for them. The connection string is the library's address and your card number.

Where you’ve seen it

A candidate preparing for a data-analyst interview runs docker run --name pg -e POSTGRES_PASSWORD=change_me -p 5432:5432 -d postgres:18, connects DBeaver to localhost:5432, loads a sample e-commerce dataset with psql -h localhost -U postgres -f shop.sql, and practises window-function questions against realistic tables.

Words you’ll hear

Server
The running database process (postgres, mysqld) that stores data and executes queries.
Client
A program that connects to the server and sends SQL: psql, mysql, DBeaver, pgAdmin.
Port
PostgreSQL listens on 5432 by default, MySQL on 3306.
Connection string
Host, port, database and user in one URL, such as postgresql://user@host:5432/db.

Visual diagram

Loading interactive diagram

Theory & example queries

Installing a local server

Docker is the most repeatable option on any operating system: docker run --name pg -e POSTGRES_PASSWORD=change_me -p 5432:5432 -v pgdata:/var/lib/postgresql -d postgres:18 starts PostgreSQL with data kept in a named volume, and docker run --name mysql -e MYSQL_ROOT_PASSWORD=change_me -p 3306:3306 -d mysql:8.4 does the same for MySQL. Without Docker, use Postgres.app or Homebrew on macOS, the official installers on Windows, or the distribution's packages (apt install postgresql) on Linux.

Check it works from the command line before reaching for a GUI: psql -h localhost -U postgres then SELECT version();. In psql, \l lists databases, \c shop switches database, \dt lists tables, \d orders describes a table and \q quits. The MySQL equivalents are SHOW DATABASES;, USE shop;, SHOW TABLES; and DESCRIBE orders;.

Create a practice database and userQuery example
1Input dataStart from the source rows or state that the statement sees.
This statement works with the current schema, configuration, or database state rather than a row dataset. The command still follows the same input → query → result flow.
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1CREATE DATABASE shop;23CREATE USER analyst4WITH5  PASSWORD 'change_me';67GRANT pg_read_all_data TO analyst;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Choose the target

Identify the table or database object the statement will modify.

1/7
3OutputInspect the representative rows, affected-row count, plan, or command status.
Representative PostgreSQL command status
CREATE DATABASE CREATE ROLE GRANT ROLE

Note: Assumes PostgreSQL 14+, an authorized superuser session, and names that do not already exist. pg_read_all_data grants read-only access to all user tables and views.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

(a built-in read-only role in PostgreSQL 14+), then connect with psql postgresql://analyst@localhost:5432/shop.

Key takeaway: Docker for a repeatable server; psql or mysql to confirm it works.

GUI clients and safe habits

DBeaver is free and connects to almost any database; pgAdmin is PostgreSQL's own tool; MySQL Workbench is MySQL's; DataGrip and TablePlus are popular paid options. All of them give you a schema browser, a query editor with autocomplete, result grids you can export, and ER diagrams of existing tables. To practise, load a sample dataset such as Pagila (PostgreSQL) or Sakila (MySQL), or import CSVs with COPY or LOAD DATA.

Good habits start locally. Most GUIs autocommit each statement, so an UPDATE without WHERE is permanent; for risky changes run BEGIN; first and check the row count before COMMIT;. Name and colour-code connections so a production connection looks different, connect to production with a read-only user, and never paste production passwords into shared files; use the client's credential store or environment variables.

A safe ad-hoc changeQuery example
1Input dataStart from the source rows or state that the statement sees.
products
3 rows
products sample rows
idnamepricecategorystock
42SQL Notebook49.5books18
84Mechanical Keyboard150hardware5
11Query Mug12.99gifts33
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1BEGIN;23UPDATE products4SET5  price = price * 1.16WHERE7  category = 'books';89SELECT10  COUNT(*)11FROM12  products13WHERE14  category = 'books';
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Start transaction

Open a transaction so changes can be checked and committed or rolled back together.

1/14
query.sql
1COMMIT;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · SQL expression

Read this line together with the surrounding statement as part of the same SQL expression.

1/1
query.sql
1ROLLBACK;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · SQL expression

Read this line together with the surrounding statement as part of the same SQL expression.

1/1
3OutputInspect the representative rows, affected-row count, plan, or command status.
Representative transaction status
BEGIN UPDATE 3 count ----- 3 COMMIT

Note: Assumes three book products matched. The final command is COMMIT only if the checked count is correct; use ROLLBACK instead to discard the update.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

and then

if the count looks right, or

if it doesn't.

Key takeaway: Any GUI works; wrap risky changes in a transaction and mark production clearly.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Install

Start a server

Run PostgreSQL or MySQL in Docker, or install it natively, with a password you set.

Focus at this step

docker run … -p 5432:5432 postgres:18

What to watch at this step
Ports
5432 · 3306
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

To practise SQL you need two things: a database server running somewhere (PostgreSQL or MySQL on your laptop, often in Docker) and a client to talk to it, either the command-line tools psql and mysql or a GUI such as DBeaver, pgAdmin or MySQL Workbench. The client connects with a host, port, database name, user and password, often written as one connection string like postgresql://app_user@localhost:5432/shop.

Why it matters: Reading about SQL only gets you so far; interview take-homes and real jobs expect you to load data, explore tables and run queries yourself. A clean local setup also teaches habits that matter at work: knowing which server you're connected to, using a separate user per purpose, and not running experiments against production.

When to reach for it

  • Practising for SQL interviews and take-homes
  • Testing a query before running it on a shared database
  • Learning a second engine's dialect

When to avoid or be careful

  • Practising on a production database
  • Using the superuser account for everyday queries
  • Running UPDATE or DELETE in autocommit mode without checking first

Ways to get a database to practise on

Docker container
Best for: Repeatable setups on any OS; switching versions

Strengths: One command to start, stop or reset; easy to run PostgreSQL and MySQL side by side.

Watch out: Needs Docker installed; data lives in volumes you must manage.

Native install
Best for: Long-term local use without Docker

Strengths: Runs as a normal service; integrates with the OS.

Watch out: Harder to remove cleanly or run several versions.

Browser playgrounds or free cloud tiers
Best for: Quick experiments with no install

Strengths: Nothing to set up.

Watch out: Limited data size and features; not your own environment.

Interview signals & numbers to know

When this topic comes up

  • “Set up a local database for this take-home”
  • “Which client do you use?”
  • “Connect to the database at this host”
  • Connection strings
  • Working safely with production

Benchmarks & rules of thumb

5432 -
PostgreSQL's default port
3306 -
MySQL's default port
1 command -
to start a server in Docker

Common mistakes & follow-ups

Common interview mistakes

  • Starting a second PostgreSQL on port 5432 while another is running, and connecting to the wrong one.
  • Running a DELETE in a GUI with autocommit on, expecting to undo it.
  • Leaving the Docker container without a volume, so the data disappears when the container is removed.

Likely interviewer follow-ups

  • How would you set up PostgreSQL locally for a take-home assignment?
  • What details does a client need to connect to a database?
  • How do you avoid accidentally changing production data from a GUI?
Interview tip: If asked about your setup, mention Docker, a GUI client and one safety habit, such as transactions for ad-hoc changes or a read-only production user. It shows you've worked with real databases.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Installing PostgreSQL / MySQL & Database Clients (DBeaver, pgAdmin) with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
SQL Dialects Overview (PostgreSQL, MySQL, SQL Server, SQLite, Oracle)
Next topic
SQL Command Categories (DDL, DML, DQL, DCL, TCL)