Installing MySQL, PostgreSQL, and SQLite | Beginner's Guide
Introduction
Before you can start writing SQL queries and working with databases, you need to install a database management system (DBMS). This section will guide you step-by-step on how to install three of the most popular relational database systems: MySQL, PostgreSQL, and SQLite.
Installing MySQL
MySQL is one of the most popular open-source relational database management systems. It’s widely used in web applications, especially with PHP (e.g., the LAMP stack).
Steps to Install MySQL:
On Windows:
- Visit the official MySQL Downloads Page.
- Download the MySQL Installer for Windows.
- Run the installer and choose "Developer Default" setup type.
- Follow the setup wizard and set a root password when prompted.
- Use MySQL Workbench or the command line to start running SQL queries.
On macOS:
- Use Homebrew:
brew install mysql
brew services start mysql
- Set the root password using:
mysql_secure_installation
On Linux (Ubuntu/Debian):
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
Installing PostgreSQL
PostgreSQL is a powerful, open-source object-relational database system known for its robustness and advanced features.
On Windows:
- Visit the official PostgreSQL Downloads Page.
- Download the PostgreSQL Installer.
- Install the PostgreSQL server, pgAdmin, and StackBuilder.
- Set your password for the
postgres
user. - Use pgAdmin or the command line to connect.
On macOS:
- Use Homebrew:
brew install postgresql
brew services start postgresql
On Linux (Ubuntu/Debian):
sudo apt update
sudo apt install postgresql postgresql-contrib
- Switch to the postgres user:
sudo -i -u postgres
psql
Installing SQLite
SQLite is a lightweight, file-based database. It's great for development and testing.
On Windows:
- Download the
sqlite-tools
ZIP file. - Extract it and add the folder to your system PATH.
- Open cmd and run:
sqlite3
On macOS:
Check if SQLite is already installed:
sqlite3 --version
If not, install it with Homebrew:
brew install sqlite
On Linux:
sudo apt update
sudo apt install sqlite3
Verifying Installation
You can verify the installations with:
- MySQL:
mysql -u root -p
- PostgreSQL:
psql -U postgres
- SQLite:
sqlite3
Conclusion
Now that you’ve successfully installed MySQL, PostgreSQL, and SQLite, you’re ready to start learning SQL and building real-world database applications.