Chapter 2: Setting Up Your Environment
Before you write your first query, it’s essential to install and configure a relational database on your workstation. A solid environment ensures you spend time learning SQL—not battling installation errors. In this chapter, we’ll:
Compare four popular RDBMS options
Walk through installation on Windows, macOS, and Linux
Demonstrate how to connect via command-line and graphical tools
Load a sample database so you can start querying immediately
By the end, your machine will be a fully functional SQL playground.
1. Choosing an RDBMS: MySQL, PostgreSQL, SQLite, SQL Server
Different relational database systems excel in different scenarios. Here’s a quick comparison to help you pick one:
| Feature | MySQL | PostgreSQL | SQLite | SQL Server |
|---|---|---|---|---|
| Use case | Web apps, LAMP stacks | Analytics, GIS, advanced SQL | Lightweight, embedded apps | Enterprise .NET, Windows ecosystems |
| Licensing | GPL (Community) / Commercial (Enterprise) | Open Source (PostgreSQL License) | Public domain | Proprietary (Developer edition free) |
| Extensibility | Plugins, limited JSON support | Advanced data types, extensions | Minimal overhead | CLR integration, T-SQL rich |
| Concurrency & Scaling | Good, with InnoDB engine | Best-in-class MVCC and parallelism | Single file, limited concurrency | Robust, enterprise clustering |
| Tooling & Community | Mature ecosystem; phpMyAdmin, Workbench | pgAdmin, DBeaver, Active community | Bare-bones CLI + many GUIs | SQL Server Management Studio (SSMS) |
If you’re unsure which to choose, PostgreSQL is a solid all-rounder. SQLite is perfect for learning or quick demos. MySQL and SQL Server are ubiquitous in web and enterprise environments, respectively.
2. Installing Your RDBMS
2.1 Windows
PostgreSQL
Download the installer from .
Run the
.exeand follow the wizard:Choose installation directory
Set a password for the
postgressuperuserSelect default port (5432)
Install StackBuilder (optional packages)
Verify installation by opening PowerShell and running:
ps1psql --versionConfirm the service is running in Services (look for “PostgreSQL”).
MySQL
Download MySQL Installer from .
Choose “Developer Default” in the installer to get MySQL Server, Workbench, Shell, and connectors.
Configure:
Select authentication method (use Strong Password Encryption)
Create a root password
Add a standard user account if desired
Set the MySQL Windows service to start automatically
Verify in PowerShell:
ps1mysql --version
SQLite
Download the precompiled binaries (
sqlite-tools-win32-x86-*.zip) from .Unzip and add the folder to your
PATHenvironment variable.Test in PowerShell:
ps1sqlite3 --version
SQL Server Developer Edition
Download from .
Run the installer, select “Developer” edition, and install.
Choose a mixed-mode authentication with an
sapassword.Install SQL Server Management Studio (SSMS) separately if not included.
Verify:
ps1sqlcmd -S localhost -U sa -P YourPassword
2.2 macOS
Homebrew Overview
On macOS, Homebrew makes installation painless. First, install Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
PostgreSQL
brew install postgresql
brew services start postgresql
psql --version
MySQL
brew install mysql
brew services start mysql
mysql_secure_installation # walk through root password setup
mysql --version
SQLite
brew install sqlite
sqlite3 --version
SQL Server (Docker)
SQL Server isn’t native on macOS, but you can run it in Docker:
docker pull mcr.microsoft.com/mssql/server:latest
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourPassword" \
-p 1433:1433 --name sqlserver -d mcr.microsoft.com/mssql/server:latest
Connect from macOS using Azure Data Studio or sqlcmd in a Docker container.
2.3 Linux (Ubuntu Example)
PostgreSQL
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo -u postgres psql -c "SELECT version();"
MySQL
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
sudo systemctl status mysql
mysql --version
SQLite
sudo apt update
sudo apt install sqlite3 libsqlite3-dev
sqlite3 --version
SQL Server (Ubuntu)
# Add Microsoft repo
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
sudo apt update
sudo apt install mssql-server
sudo /opt/mssql/bin/mssql-conf setup # choose edition, SA password
sudo systemctl status mssql-server
3. Connecting to Your Database
3.1 Command-Line Interface (CLI)
PostgreSQL (psql CLI)
psql -h localhost -U postgres -d postgres
# Enter password when prompted
Key commands:
\llist databases\c dbnameconnect to database\dtlist tables\qquit
MySQL (mysql CLI)
mysql -h localhost -u root -p
Key commands:
SHOW DATABASES;USE dbname;SHOW TABLES;EXIT;
SQLite (sqlite3 CLI)
sqlite3 /path/to/database.db
Key commands:
.tables.schema tablename.quit
SQL Server (sqlcmd)
sqlcmd -S localhost -U sa -P YourPassword
Key commands:
SELECT name FROM sys.databases; GOUSE YourDatabase; GOSELECT * FROM YourTable; GOEXIT
3.2 Graphical Tools
Using a GUI can speed up development and exploration.
pgAdmin (PostgreSQL): Create servers, manage objects, run queries.
MySQL Workbench: Visual database design, query editor, performance dashboard.
DBeaver / HeidiSQL: Multi-dialect clients supporting MySQL, PostgreSQL, SQLite, SQL Server.
Azure Data Studio / SSMS: Microsoft tools for SQL Server.
To connect, simply open your chosen tool, enter host (localhost), port (e.g., 5432, 3306, 1433), username, and password. Test the connection and save a profile for quick access.
4. Loading a Sample Database
A sample dataset helps you practice writing queries immediately. We’ll load the classic “Pagila” schema for PostgreSQL and “sakila” for MySQL, both based on a DVD rental business.
4.1 PostgreSQL: Pagila
Download the SQL files:
Create the database and load schema:
bashcreatedb pagila psql -d pagila -f pagila-schema.sql psql -d pagila -f pagila-data.sqlVerify:
bashpsql -d pagila -c "\dt"
4.2 MySQL: Sakila
Download from MySQL site:
Create and load:
bashmysql -u root -p CREATE DATABASE sakila; USE sakila; SOURCE /path/to/sakila-schema.sql; SOURCE /path/to/sakila-data.sql;Verify:
sqlSHOW TABLES;
4.3 SQLite: Chinook
Chinook is a music store sample:
Download
Chinook_Sqlite.sqlitefrom .Open in CLI or GUI:
bashsqlite3 Chinook_Sqlite.sqlite .tables
4.4 SQL Server: AdventureWorks
Download the backup from Microsoft:
Restore via SSMS or
sqlcmd:sqlRESTORE DATABASE AdventureWorks FROM DISK = 'C:\Backups\AdventureWorks.bak' WITH MOVE 'AdventureWorks_Data' TO 'C:\MSSQL\Data\AdventureWorks.mdf', MOVE 'AdventureWorks_Log' TO 'C:\MSSQL\Data\AdventureWorks.ldf';Verify with SSMS Object Explorer.
5. Your SQL Playground Is Ready
Congratulations! You now have:
A relational database engine installed
Command-line and graphical tools connected
A sample database loaded and ready for queries
In the next chapter, we’ll dive into basic SELECT statements—retrieving and filtering data to answer real questions. Fire up your SQL client and get ready to explore tables, filter rows, and sort results. Your data-driven journey begins now!

Comments
Post a Comment