How to Set Up Your SQL Environment (Step-by-Step)
You have learned what SQL is and how databases organize data into tables, rows, and columns. Now it is time to get your hands dirty. Before you can write your first query, you need a working SQL environment, a place where you can create databases, run queries, and see results.
The good news is that setting up an SQL environment has never been easier. Whether you want to start practicing in the next 30 seconds using an online tool, install a full database system on your machine, or work directly from the command line, this guide covers every option step by step. By the end, you will have a fully functional SQL environment loaded with a sample database, and you will have executed your very first query.
Let us get started.
Choosing the Right Setup for You
There are three main ways to set up your SQL environment. Each has its strengths, and the right choice depends on your goals and comfort level.
| Option | Best For | Time to Start | Requires Installation |
|---|---|---|---|
| Online tools | Absolute beginners, quick practice | Under 1 minute | No |
| Local install with GUI | Ongoing learning, real projects | 15-30 minutes | Yes |
| Command line | Developers who prefer terminal workflows | 10-20 minutes | Yes |
If you are setting up SQL for the very first time, start with an online tool. You can begin writing queries immediately without installing anything. Once you feel comfortable with the basics, move to a local installation for a more complete experience.
Option A: Online SQL Environments (No Installation)
Online SQL tools run entirely in your browser. There is nothing to download, nothing to configure, and nothing that can go wrong with your local setup. Open a URL, start writing SQL.
DB Fiddle
DB Fiddle (https://www.db-fiddle.com) is one of the most popular online SQL playgrounds. It supports multiple database engines and lets you share your queries with others via URL.
How to get started:
- Open your browser and navigate to https://www.db-fiddle.com
- In the top-left dropdown, select your preferred database engine (choose PostgreSQL 15 or MySQL 8.0 for the most standard experience)
- On the left panel, paste your table creation and data insertion statements (this is your "Schema SQL")
- On the right panel, write your
SELECTqueries - Click Run to execute
Here is a quick test to verify everything works. Paste this into the left panel (Schema SQL):
CREATE TABLE products (
id INTEGER PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10, 2)
);
INSERT INTO products VALUES (1, 'Wireless Mouse', 29.99);
INSERT INTO products VALUES (2, 'Mechanical Keyboard', 89.99);
INSERT INTO products VALUES (3, 'USB-C Hub', 45.00);
Then paste this into the right panel (Query SQL):
SELECT * FROM products WHERE price > 30;
Click Run, and you should see:
| id | name | price |
|---|---|---|
| 2 | Mechanical Keyboard | 89.99 |
| 3 | USB-C Hub | 45.00 |
If you see that result, your online environment is working perfectly.
SQLite Online
SQLite Online (https://sqliteonline.com) provides a clean, straightforward interface specifically for SQLite databases. It is excellent for beginners because SQLite has the simplest syntax with the fewest configuration options.
How to get started:
- Navigate to https://sqliteonline.com
- You will see a query editor already loaded with a sample database
- Clear the existing content and type your own SQL statements
- Click Run to execute
SQLite Online also lets you import and export database files, which is useful when you want to save your progress.
Other Online Options
| Tool | URL | Notes |
|---|---|---|
| SQL Fiddle | http://sqlfiddle.com | Similar to DB Fiddle, supports multiple engines |
| PostgreSQL Exercises | https://pgexercises.com | Guided exercises with a pre-loaded database |
| Mode Analytics SQL Tutorial | https://mode.com/sql-tutorial | Interactive lessons with real datasets |
| W3Schools SQL Tryit | https://www.w3schools.com/sql/trysql.asp | Simple editor with a pre-loaded sample database |
Online SQL environments are perfect for learning and quick experiments, but they come with limitations. You cannot create persistent databases that survive after closing the browser tab (in most tools), you cannot handle large datasets, and you cannot connect them to real applications. For serious work, you will eventually need a local installation.
Option B: Local Installation with a GUI
Installing a database system locally gives you the full experience: persistent databases, better performance, advanced features, and the ability to connect your database to real applications. A GUI (Graphical User Interface) tool makes this process beginner-friendly by providing visual interfaces for managing your databases.
We will cover the three most popular setups: SQLite with DB Browser, PostgreSQL with pgAdmin, and MySQL with MySQL Workbench.
SQLite with DB Browser (Easiest Local Setup)
SQLite is the simplest database to install because there is almost nothing to install. SQLite is a file-based database, meaning your entire database is a single file on your computer. No server to run, no configuration needed.
DB Browser for SQLite is a free visual tool for creating, designing, and editing SQLite database files.
Installation steps:
- Go to https://sqlitebrowser.org/dl/
- Download the installer for your operating system (Windows, macOS, or Linux)
- Run the installer and follow the default prompts
- Launch DB Browser for SQLite
Creating your first database:
- Click New Database in the toolbar
- Choose a location and name for your file (e.g.,
my_first_database.db) - A dialog will appear asking you to create a table. You can do it visually or click Cancel and use SQL instead
- Click the Execute SQL tab
- Type your SQL statements and click the Play button (or press
F5) to run them
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username VARCHAR(30) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO users (username, email) VALUES ('alice', 'alice@example.com');
INSERT INTO users (username, email) VALUES ('bob', 'bob@example.com');
SELECT * FROM users;
Output:
| id | username | created_at | |
|---|---|---|---|
| 1 | alice | alice@example.com | 2024-06-15 10:30:00 |
| 2 | bob | bob@example.com | 2024-06-15 10:30:01 |
SQLite is the perfect "training wheels" database. It requires zero configuration, runs everywhere, and supports standard SQL syntax. Many professional applications also use SQLite in production (it powers most mobile apps, including every iOS and Android device). Learning SQLite is never wasted effort.
PostgreSQL with pgAdmin
PostgreSQL is the most feature-rich open-source relational database. It is widely used in professional environments, supports advanced SQL features, and is the database many developers recommend learning "properly" with. pgAdmin is the official GUI management tool for PostgreSQL.
Installation steps (Windows):
- Go to https://www.postgresql.org/download/windows/
- Click Download the installer (provided by EDB)
- Run the installer
- During installation, you will be asked to:
- Choose an installation directory (default is fine)
- Select components: make sure PostgreSQL Server and pgAdmin 4 are both checked
- Set a password for the superuser (the default superuser is
postgres). Remember this password! - Keep the default port (
5432)
- Complete the installation
Installation steps (macOS):
-
The easiest method is using Homebrew. Open Terminal and run:
brew install postgresql@16
brew services start postgresql@16 -
Install pgAdmin separately by downloading it from https://www.pgadmin.org/download/
Installation steps (Linux/Ubuntu):
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
Install pgAdmin by following the instructions at https://www.pgadmin.org/download/pgadmin-4-apt/
Connecting pgAdmin to your PostgreSQL server:
- Open pgAdmin 4
- In the left panel, right-click Servers and select Register > Server
- In the General tab, give your server a name (e.g.,
Local PostgreSQL) - In the Connection tab:
- Host:
localhost - Port:
5432 - Username:
postgres - Password: the password you set during installation
- Host:
- Click Save
Creating a database and running queries:
- Right-click your server in the left panel, select Create > Database
- Name it
practice_dband click Save - Right-click
practice_dband select Query Tool - Type your SQL and click the Execute/Play button (or press
F5)
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
price DECIMAL(10, 2) CHECK (price > 0),
category VARCHAR(50),
in_stock BOOLEAN DEFAULT true
);
INSERT INTO products (name, price, category)
VALUES ('Laptop Stand', 49.99, 'Accessories');
INSERT INTO products (name, price, category)
VALUES ('Webcam HD', 79.99, 'Electronics');
SELECT * FROM products;
If you see an error like FATAL: password authentication failed for user "postgres", it means the password you entered does not match what was set during installation. On Linux, you can reset it:
sudo -u postgres psql
\password postgres
Type your new password, then try connecting again in pgAdmin.
MySQL with MySQL Workbench
MySQL is one of the most widely deployed databases in the world, especially popular in web development (it powers WordPress, Drupal, and many PHP-based applications). MySQL Workbench is the official GUI tool.
Installation steps:
- Go to https://dev.mysql.com/downloads/installer/ (Windows) or https://dev.mysql.com/downloads/mysql/ (macOS/Linux)
- Download the MySQL Installer (choose the full version)
- Run the installer and select Developer Default setup type
- This will install both MySQL Server and MySQL Workbench
- During configuration:
- Keep the default port (
3306) - Set a root password. Remember this password!
- Optionally create additional user accounts
- Keep the default port (
- Complete the installation
macOS alternative using Homebrew:
brew install mysql
brew services start mysql
mysql_secure_installation
Then download MySQL Workbench separately from https://dev.mysql.com/downloads/workbench/
Connecting MySQL Workbench:
- Open MySQL Workbench
- On the home screen, click the + icon next to "MySQL Connections"
- Enter connection details:
- Connection Name:
Local MySQL - Hostname:
127.0.0.1 - Port:
3306 - Username:
root
- Connection Name:
- Click Test Connection, enter your root password, and confirm it works
- Click OK to save
Creating a database and running queries:
- Click on your saved connection to open it
- In the query editor, run:
CREATE DATABASE practice_db;
USE practice_db;
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE
);
INSERT INTO customers (first_name, last_name, email)
VALUES ('Alice', 'Johnson', 'alice@example.com');
SELECT * FROM customers;
- Click the lightning bolt icon to execute
DBeaver: A Universal GUI for Any Database
If you want a single tool that works with any database system, DBeaver is an excellent free, open-source option. It supports PostgreSQL, MySQL, SQLite, SQL Server, Oracle, and dozens more.
Installation:
- Download from https://dbeaver.io/download/
- Install using the default settings
- On first launch, DBeaver will guide you through creating a database connection
- Select your database type, enter your connection details, and you are ready to go
DBeaver provides a consistent interface regardless of which database you are using, making it a popular choice for developers who work with multiple database systems.
Option C: Command Line Interface
For developers who prefer working in the terminal, each database system provides a command-line client. This approach is lightweight, fast, and gives you the most direct interaction with your database.
SQLite from the Command Line
SQLite comes pre-installed on macOS and most Linux distributions. Windows users can download it from https://www.sqlite.org/download.html.
Starting SQLite:
# Create (or open) a database file
sqlite3 my_database.db
You will see the SQLite prompt:
SQLite version 3.43.0 2023-08-24 12:36:59
Enter ".help" for usage hints.
sqlite>
Running queries:
sqlite> CREATE TABLE books (
...> id INTEGER PRIMARY KEY,
...> title TEXT NOT NULL,
...> author TEXT NOT NULL,
...> year INTEGER
...> );
sqlite> INSERT INTO books VALUES (1, '1984', 'George Orwell', 1949);
sqlite> INSERT INTO books VALUES (2, 'Dune', 'Frank Herbert', 1965);
sqlite> SELECT * FROM books;
1|1984|George Orwell|1949
2|Dune|Frank Herbert|1965
Useful SQLite commands:
| Command | Description |
|---|---|
.tables | List all tables in the database |
.schema tablename | Show the CREATE statement for a table |
.headers on | Display column headers in query results |
.mode column | Format output in aligned columns |
.quit | Exit SQLite |
Make the output more readable:
sqlite> .headers on
sqlite> .mode column
sqlite> SELECT * FROM books;
id title author year
-- ----- ------------- ----
1 1984 George Orwell 1949
2 Dune Frank Herbert 1965
PostgreSQL from the Command Line (psql)
psql is the interactive terminal for PostgreSQL.
Connecting:
# Connect as the postgres user to the default database
psql -U postgres
# Connect to a specific database
psql -U postgres -d practice_db
Running queries:
postgres=# CREATE DATABASE practice_db;
CREATE DATABASE
postgres=# \c practice_db
You are now connected to database "practice_db".
practice_db=# CREATE TABLE employees (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(50)
);
practice_db=# INSERT INTO employees (name, department)
VALUES ('Alice', 'Engineering');
practice_db=# SELECT * FROM employees;
id | name | department
----+-------+-------------
1 | Alice | Engineering
(1 row)
Useful psql commands:
| Command | Description |
|---|---|
\l | List all databases |
\dt | List all tables in the current database |
\d tablename | Describe a table's structure |
\c dbname | Connect to a different database |
\q | Quit psql |
\? | Show help for psql commands |
MySQL from the Command Line
Connecting:
mysql -u root -p
You will be prompted for your password. After entering it:
mysql> CREATE DATABASE practice_db;
Query OK, 1 row affected (0.01 sec)
mysql> USE practice_db;
Database changed
mysql> CREATE TABLE tasks (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200) NOT NULL,
is_done BOOLEAN DEFAULT false
);
mysql> INSERT INTO tasks (title) VALUES ('Learn SQL basics');
mysql> INSERT INTO tasks (title) VALUES ('Set up database');
mysql> SELECT * FROM tasks;
+----+------------------+--------+
| id | title | is_done|
+----+------------------+--------+
| 1 | Learn SQL basics | 0 |
| 2 | Set up database | 0 |
+----+------------------+--------+
2 rows in set (0.00 sec)
Useful MySQL commands:
| Command | Description |
|---|---|
SHOW DATABASES; | List all databases |
SHOW TABLES; | List all tables in the current database |
DESCRIBE tablename; | Show a table's structure |
USE dbname; | Switch to a different database |
EXIT; or \q | Quit MySQL |
Loading the ShopSmart Sample Database
Now that your environment is ready, let us load a sample database that you can use for practicing throughout your SQL learning journey. We will create a small e-commerce database called ShopSmart with realistic data across multiple related tables.
This database works with any of the setups described above. Copy the following SQL statements into your environment and execute them.
The SQL below uses standard syntax that works in PostgreSQL and SQLite. For MySQL, replace SERIAL with INT AUTO_INCREMENT and BOOLEAN values true/false with 1/0. The core queries will work identically across all three systems.
Creating the ShopSmart Tables
-- Customers table
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
city VARCHAR(50),
signup_date DATE
);
-- Product categories
CREATE TABLE categories (
id INTEGER PRIMARY KEY,
name VARCHAR(50) NOT NULL,
description TEXT
);
-- Products table
CREATE TABLE products (
id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
category_id INTEGER,
price DECIMAL(10, 2) NOT NULL,
stock_quantity INTEGER DEFAULT 0,
is_available BOOLEAN DEFAULT true,
FOREIGN KEY (category_id) REFERENCES categories(id)
);
-- Orders table
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer_id INTEGER NOT NULL,
order_date DATE NOT NULL,
total_amount DECIMAL(10, 2),
status VARCHAR(20) DEFAULT 'pending',
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
-- Order items (products in each order)
CREATE TABLE order_items (
id INTEGER PRIMARY KEY,
order_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
quantity INTEGER NOT NULL CHECK (quantity > 0),
unit_price DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
Inserting Sample Data
-- Insert categories
INSERT INTO categories VALUES (1, 'Electronics', 'Gadgets, devices, and accessories');
INSERT INTO categories VALUES (2, 'Books', 'Physical and digital books');
INSERT INTO categories VALUES (3, 'Home & Kitchen', 'Items for home and kitchen use');
INSERT INTO categories VALUES (4, 'Sports', 'Sports equipment and accessories');
-- Insert customers
INSERT INTO customers VALUES (1, 'Alice', 'Johnson', 'alice@email.com', 'New York', '2023-01-15');
INSERT INTO customers VALUES (2, 'Bob', 'Martinez', 'bob@email.com', 'Los Angeles', '2023-03-22');
INSERT INTO customers VALUES (3, 'Carol', 'Singh', 'carol@email.com', 'Chicago', '2023-06-10');
INSERT INTO customers VALUES (4, 'David', 'Chen', 'david@email.com', 'New York', '2023-08-05');
INSERT INTO customers VALUES (5, 'Eva', 'Brown', 'eva@email.com', 'Seattle', '2024-01-18');
INSERT INTO customers VALUES (6, 'Frank', 'Wilson', 'frank@email.com', 'Chicago', '2024-02-28');
-- Insert products
INSERT INTO products VALUES (1, 'Wireless Mouse', 1, 29.99, 150, true);
INSERT INTO products VALUES (2, 'Mechanical Keyboard', 1, 89.99, 75, true);
INSERT INTO products VALUES (3, 'USB-C Hub', 1, 45.00, 200, true);
INSERT INTO products VALUES (4, 'SQL for Beginners', 2, 34.99, 50, true);
INSERT INTO products VALUES (5, 'Data Science Handbook', 2, 42.50, 30, true);
INSERT INTO products VALUES (6, 'Coffee Maker Pro', 3, 129.99, 25, true);
INSERT INTO products VALUES (7, 'Yoga Mat Premium', 4, 38.00, 100, true);
INSERT INTO products VALUES (8, 'Running Shoes X1', 4, 110.00, 60, true);
INSERT INTO products VALUES (9, 'Bluetooth Speaker', 1, 65.00, 0, false);
INSERT INTO products VALUES (10, 'Stainless Water Bottle', 4, 24.99, 180, true);
-- Insert orders
INSERT INTO orders VALUES (1, 1, '2024-01-10', 119.98, 'completed');
INSERT INTO orders VALUES (2, 2, '2024-01-15', 89.99, 'completed');
INSERT INTO orders VALUES (3, 1, '2024-02-20', 77.49, 'completed');
INSERT INTO orders VALUES (4, 3, '2024-03-05', 129.99, 'shipped');
INSERT INTO orders VALUES (5, 4, '2024-03-12', 155.00, 'shipped');
INSERT INTO orders VALUES (6, 5, '2024-03-20', 34.99, 'pending');
INSERT INTO orders VALUES (7, 2, '2024-04-01', 63.00, 'pending');
INSERT INTO orders VALUES (8, 6, '2024-04-10', 199.98, 'pending');
-- Insert order items
INSERT INTO order_items VALUES (1, 1, 1, 2, 29.99);
INSERT INTO order_items VALUES (2, 1, 3, 1, 45.00);
INSERT INTO order_items VALUES (3, 2, 2, 1, 89.99);
INSERT INTO order_items VALUES (4, 3, 4, 1, 34.99);
INSERT INTO order_items VALUES (5, 3, 10, 1, 24.99);
INSERT INTO order_items VALUES (6, 4, 6, 1, 129.99);
INSERT INTO order_items VALUES (7, 5, 8, 1, 110.00);
INSERT INTO order_items VALUES (8, 5, 3, 1, 45.00);
INSERT INTO order_items VALUES (9, 6, 4, 1, 34.99);
INSERT INTO order_items VALUES (10, 7, 7, 1, 38.00);
INSERT INTO order_items VALUES (11, 7, 10, 1, 24.99);
INSERT INTO order_items VALUES (12, 8, 2, 1, 89.99);
INSERT INTO order_items VALUES (13, 8, 8, 1, 110.00);
Verifying the Data
After loading the data, run these quick verification queries to make sure everything is set up correctly:
-- Check row counts for each table
SELECT 'customers' AS table_name, COUNT(*) AS row_count FROM customers
UNION ALL
SELECT 'categories', COUNT(*) FROM categories
UNION ALL
SELECT 'products', COUNT(*) FROM products
UNION ALL
SELECT 'orders', COUNT(*) FROM orders
UNION ALL
SELECT 'order_items', COUNT(*) FROM order_items;
Expected output:
| table_name | row_count |
|---|---|
| customers | 6 |
| categories | 4 |
| products | 10 |
| orders | 8 |
| order_items | 13 |
If your row counts match, the ShopSmart database is loaded and ready to use.
Running Your Very First Queries
With the ShopSmart database loaded, let us run a few queries to confirm everything works and give you a taste of what SQL can do.
Query 1: View All Products
SELECT name, price, stock_quantity
FROM products
ORDER BY price DESC;
Output:
| name | price | stock_quantity |
|---|---|---|
| Coffee Maker Pro | 129.99 | 25 |
| Running Shoes X1 | 110.00 | 60 |
| Mechanical Keyboard | 89.99 | 75 |
| Bluetooth Speaker | 65.00 | 0 |
| USB-C Hub | 45.00 | 200 |
| Data Science Handbook | 42.50 | 30 |
| Yoga Mat Premium | 38.00 | 100 |
| SQL for Beginners | 34.99 | 50 |
| Wireless Mouse | 29.99 | 150 |
| Stainless Water Bottle | 24.99 | 180 |
Query 2: Find Customers from New York
SELECT first_name, last_name, email
FROM customers
WHERE city = 'New York';
Output:
| first_name | last_name | |
|---|---|---|
| Alice | Johnson | alice@email.com |
| David | Chen | david@email.com |
Query 3: Count Products by Category
SELECT c.name AS category, COUNT(p.id) AS product_count
FROM categories c
LEFT JOIN products p ON c.id = p.category_id
GROUP BY c.name
ORDER BY product_count DESC;
Output:
| category | product_count |
|---|---|
| Electronics | 4 |
| Sports | 3 |
| Books | 2 |
| Home & Kitchen | 1 |
Query 4: Find Recent Orders with Customer Names
SELECT o.id AS order_id,
c.first_name || ' ' || c.last_name AS customer,
o.order_date,
o.total_amount,
o.status
FROM orders o
JOIN customers c ON o.customer_id = c.id
ORDER BY o.order_date DESC
LIMIT 5;
Output:
| order_id | customer | order_date | total_amount | status |
|---|---|---|---|---|
| 8 | Frank Wilson | 2024-04-10 | 199.98 | pending |
| 7 | Bob Martinez | 2024-04-01 | 63.00 | pending |
| 6 | Eva Brown | 2024-03-20 | 34.99 | pending |
| 5 | David Chen | 2024-03-12 | 155.00 | shipped |
| 4 | Carol Singh | 2024-03-05 | 129.99 | shipped |
The || operator for combining strings works in PostgreSQL and SQLite. In MySQL, use the CONCAT() function instead:
-- MySQL version
SELECT CONCAT(c.first_name, ' ', c.last_name) AS customer
FROM customers c;
Query 5: Explore Product Details in an Order
SELECT o.id AS order_id,
p.name AS product,
oi.quantity,
oi.unit_price,
(oi.quantity * oi.unit_price) AS line_total
FROM order_items oi
JOIN orders o ON oi.order_id = o.id
JOIN products p ON oi.product_id = p.id
WHERE o.id = 1;
Output:
| order_id | product | quantity | unit_price | line_total |
|---|---|---|---|---|
| 1 | Wireless Mouse | 2 | 29.99 | 59.98 |
| 1 | USB-C Hub | 1 | 45.00 | 45.00 |
This query shows all items in order #1, combining data from three different tables in a single result. This is the relational model at work.
Troubleshooting Common Setup Issues
Even with straightforward installations, you may encounter a few common issues. Here are the most frequent ones and how to resolve them.
"Connection Refused" Error
Cause: The database server is not running.
Solution:
# PostgreSQL
sudo systemctl start postgresql # Linux
brew services start postgresql@16 # macOS
# MySQL
sudo systemctl start mysql # Linux
brew services start mysql # macOS
"Access Denied" or "Authentication Failed"
Cause: Incorrect username or password.
Solution: Double-check the credentials you set during installation. If you forgot your password, you will need to reset it:
# PostgreSQL password reset
sudo -u postgres psql
\password postgres
# MySQL password reset
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
"Command Not Found" in Terminal
Cause: The database client is not in your system's PATH.
Solution: Either add the installation directory to your PATH or use the full path to the executable:
# Example: full path for PostgreSQL on macOS (Homebrew)
/opt/homebrew/opt/postgresql@16/bin/psql -U postgres
# Example: full path for MySQL on Windows
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe" -u root -p
"Syntax Error" When Running SQL
Cause: Small syntax differences between database engines.
-- This works in MySQL but NOT in PostgreSQL or SQLite
CREATE TABLE test (
id INT AUTO_INCREMENT PRIMARY KEY
);
-- PostgreSQL equivalent
CREATE TABLE test (
id SERIAL PRIMARY KEY
);
-- SQLite equivalent
CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT
);
Always check that your SQL syntax matches the specific database engine you are using.
Summary
You now have everything you need to start practicing SQL with a real environment and real data. Here is a quick recap of what was covered:
- Online tools (DB Fiddle, SQLite Online) let you start in seconds with zero installation
- Local GUI tools (DB Browser for SQLite, pgAdmin, MySQL Workbench, DBeaver) provide a complete, persistent environment for serious learning and development
- Command-line clients (
sqlite3,psql,mysql) offer a fast, lightweight way to interact with databases directly from the terminal - The ShopSmart sample database gives you 5 interconnected tables with realistic e-commerce data to practice with
- Your first queries demonstrated
SELECT,WHERE,JOIN,GROUP BY,ORDER BY, andLIMIT, covering a solid range of fundamental SQL operations
Pick the setup that feels most comfortable, load the ShopSmart database, and start experimenting. The best way to learn SQL is to write queries, see results, tweak them, and repeat. Your environment is ready. Now the real learning begins.