Setting Up MySQL
MySQL is the world's most popular open-source relational database. Before you can write real SQL you need a working installation. In this chapter you'll download, install, and verify MySQL on your machine — and get MySQL Workbench running so you can execute your first live queries straight away.
Why MySQL?
There are many relational database systems — PostgreSQL, SQLite, MS SQL Server, Oracle. So why start with MySQL? Because it is the most widely deployed, most beginner-friendly, and completely free option available today.
MySQL Editions
MySQL ships in several editions. For learning — and for the vast majority of web projects — always grab the free Community Edition.
| Edition | Cost | Best For | Support |
|---|---|---|---|
| Community | Free | Learning, startups, web apps | Community forums |
| Standard | Paid | Growing production workloads | Oracle business hours |
| Enterprise | Paid | Mission-critical, regulated industries | Oracle 24/7 SLA |
Installation
Select your operating system below. The steps differ slightly per platform but the end result is identical — a running MySQL 8 server on port 3306 that you can connect to locally.
mysql-installer-community-8.x.x.msi (~500 MB).
Avoid the small "web" installer; it requires an active internet connection
during setup.
3306. For authentication
choose Use Strong Password Encryption — this is the correct
setting for MySQL 8.# Check version
C:\> mysql --version
mysql Ver 8.0.xx Distrib 8.0.xx, for Win64
# Connect to MySQL shell
C:\> mysql -u root -p
# Enter your root password when prompted
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install mysql
brew services start mysql
mysql_secure_installation # set root password & harden the install
mysql --version
mysql -u root -p
apt with dnf.
sudo apt update
sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql # auto-start on boot
sudo mysql_secure_installation
sudo mysql
CREATE USER 'student'@'localhost' IDENTIFIED BY 'StrongPass123!';
GRANT ALL PRIVILEGES ON *.* TO 'student'@'localhost';
FLUSH PRIVILEGES;
EXIT;
# Connect as the new user
mysql -u student -p
MySQL Workbench — The Visual GUI
MySQL Workbench is the official graphical client for MySQL. It gives you a visual query editor, schema designer, server monitor, user manager, and data export — all in one window. On Windows it is included in the Developer Default install. On macOS and Linux, download it separately from dev.mysql.com/downloads/workbench.
-- Ctrl+Enter to run the selected query
SELECT s.id, s.name, s.city, c.course_name, e.enrolled_at FROM students s JOIN enrollments e ON e.student_id = s.id JOIN courses c ON c.id = e.course_id WHERE s.city = 'Vadodara' ORDER BY e.enrolled_at DESC LIMIT 10;
Verify Your Installation
Run these four commands inside the MySQL shell (or in a Workbench query tab) to confirm everything is working correctly:
-- 1. Check MySQL server version
SELECT VERSION();
-- 2. List all databases on this server
SHOW DATABASES;
-- 3. Who am I, what time is it?
SELECT USER(), NOW();
-- 4. How long has the server been running?
SHOW STATUS LIKE 'Uptime';
Expected output from SHOW DATABASES on a clean installation:
| Database |
|---|
| information_schema |
| mysql |
| performance_schema |
| sys |
mysql, information_schema, performance_schema, or sys
— these are MySQL's internal system databases required for the server to function correctly.
How MySQL Architecture Works
Understanding how the layers fit together helps you debug connection issues and optimise performance later on. Here is the full MySQL component stack, from your client all the way down to disk:
Key Configuration Reference
MySQL reads its configuration from my.ini on Windows or /etc/mysql/my.cnf on Linux / macOS. You rarely need to edit this as a beginner, but knowing the defaults helps you interpret connection errors and performance warnings:
| Setting | Default | What it controls |
|---|---|---|
| port | 3306 | TCP port MySQL listens on. Change only if another service already uses 3306 — update all client connection strings too. |
| bind-address | 127.0.0.1 | Only accepts local connections. Set to 0.0.0.0
to allow remote clients (always pair with firewall rules). |
| max_connections | 151 | Maximum simultaneous client connections. Raise for busy applications — but each open connection consumes RAM. |
| innodb_buffer_pool_size | 128 MB | RAM allocated to InnoDB's data cache. Set to ~70% of total RAM for a dedicated database server to maximise performance. |
| character_set_server | utf8mb4 | Default character set. utf8mb4 supports full
Unicode including emoji — always keep this default. |
| slow_query_log | OFF | Enable to log queries slower than long_query_time. Essential for diagnosing
performance bottlenecks in production. |
Try It Yourself
You don't need MySQL installed to practice SQL right now. Use the in-browser
runner below — it simulates SELECT queries against our built-in students table. Once MySQL is installed on your machine, paste
these same queries into Workbench to run them for real.
students (id, name, email, city, course, grade)
· Try:
What is the default port that MySQL listens on?
Which MySQL edition is completely free and open-source?
On Linux, which command secures a fresh MySQL install by setting the root password and removing anonymous test accounts?
- MySQL Community Edition is free, open-source, and the right choice for learning and most web applications.
- On Windows: use the MySQL Installer (.msi) with "Developer Default" — it includes Workbench, Shell, and all connectors automatically.
- On macOS: the easiest path is brew install mysql followed by mysql_secure_installation.
- On Linux: sudo apt install mysql-server then run mysql_secure_installation to harden the installation.
- MySQL Workbench is the official visual GUI — use it to write queries, browse schemas, manage users, and export data.
- MySQL's default port is 3306. Always set a strong root password — never leave it blank even on a local machine.
- Verify a healthy install with SELECT VERSION(); and SHOW DATABASES; from the shell or Workbench.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.