Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. SQL Dictionary
  3. [Setup] SQL Execution Environment

[Setup] SQL Execution Environment

This page explains how to set up a SQL development environment. SQL is a language for working with databases. Options range from the lightweight SQLite to full-featured MySQL and PostgreSQL.

Getting Started with SQLite (Easiest)

SQLite is a lightweight database that requires no server installation. It is ideal for learning or quick experiments.

OSInstallation Method
WindowsDownload sqlite-tools from sqlite.org and extract it. Add the folder path to the PATH environment variable.
macOSSQLite comes pre-installed on macOS. No additional installation is needed.

Run the following command in a terminal to launch SQLite's interactive mode.

sqlite3 test.db

You can type and run SQL in interactive mode.

-- Create a table
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    age INTEGER
);

-- Insert data
INSERT INTO users (name, age) VALUES ('Alice', 25);
INSERT INTO users (name, age) VALUES ('Bob', 30);

-- Retrieve data
SELECT * FROM users;
-- Output:
-- 1|Alice|25
-- 2|Bob|30

-- Quit
.quit

Installing and Connecting to MySQL

MySQL is one of the most widely used databases. It is frequently adopted in web application development.

OSInstallation Method
WindowsDownload and run MySQL Installer from the official MySQL website.
macOSRun brew install mysql with Homebrew, then start the server with brew services start mysql.

After installation, connect to MySQL with the following command.

-- Connect to MySQL (use the password set during installation)
mysql -u root -p

-- Create a database
CREATE DATABASE mydb;

-- Select the database
USE mydb;

-- From here, standard SQL can be executed
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INT
);

Installing and Connecting to PostgreSQL

PostgreSQL is a powerful and reliable database. It is well suited for complex queries and large-scale systems.

OSInstallation Method
WindowsDownload and run the installer from the official PostgreSQL website.
macOSRun brew install postgresql@16 with Homebrew, then start the server with brew services start postgresql@16.

After installation, connect with the following command.

-- Connect to PostgreSQL
psql -U postgres

-- Create a database
CREATE DATABASE mydb;

-- Connect to the database
\c mydb

-- Table creation and data operations are nearly the same as MySQL
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INTEGER
);

Try SQL Online

There are also services that let you try SQL directly from a browser without installation. They are recommended if you want to get familiar with SQL syntax before setting up a local environment.

ServiceFeatures
DB FiddleSupports MySQL, PostgreSQL, and SQLite. Write table definitions on the left and queries on the right, then run them.
SQLite OnlineAn online editor focused on SQLite. The simple interface lets you try SQL immediately.

Online services are convenient, but data is not saved. For serious learning or development, setting up a local environment is recommended.

Command Not Found

If the terminal shows sqlite3: command not found, mysql: command not found, or psql: command not found, the PATH may not be configured correctly. Follow the steps below to check and set it up.

1. Locate the command

Check where the command you want to use is installed.

which sqlite3
which mysql
which psql

If not found, check the common installation paths.

SQLite:

ls /usr/bin/sqlite3
ls /usr/local/bin/sqlite3

MySQL:

ls /usr/local/mysql/bin/mysql
ls /opt/homebrew/bin/mysql

PostgreSQL:

ls /usr/local/bin/psql
ls /opt/homebrew/bin/psql
ls /usr/local/pgsql/bin/psql

2. Check your shell

echo $SHELL

If the output is /bin/zsh, edit ~/.zshrc. If it is /bin/bash, edit ~/.bashrc.

3. Add the path to PATH

Once you know the installation path, add it to your shell configuration file.

For macOS (zsh) — MySQL example:

echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

For Linux (bash) — PostgreSQL example:

echo 'export PATH="/usr/local/pgsql/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

On Windows, go to "System Properties" → "Environment Variables" → "Path" and add the installation folder for your database client (e.g., for MySQL: C:\Program Files\MySQL\MySQL Server 8.0\bin).

If you find any errors or copyright issues, please .