Tutorials SQL Setting Up MySQL
Ch 4 / 69
Advertisement
📢 Ad space · 728 × 90 · Replace slot ID above
Chapter 4 Beginner 8 min read MySQL

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.

What you'll learn
Why MySQL is the right choice for beginners
The difference between MySQL editions
Installing MySQL on Windows step by step
Installing MySQL on macOS and Linux
Using MySQL Workbench as a visual GUI client
Verifying your installation is healthy

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.

Most Widely Used
Powers Facebook, YouTube, Twitter, Wikipedia, and millions of web apps worldwide. MySQL skills are immediately valuable in the job market.
Free & Open Source
The Community Edition is completely free under the GPL licence. You never need to pay to learn or build production applications with it.
High Performance
Handles millions of queries per second with proper indexing. Scales from a Raspberry Pi all the way to billion-row cloud databases.
Industry Standard
Most SQL job postings list MySQL. The SQL you learn here transfers directly to PostgreSQL, SQLite, and SQL Server with minimal changes.
Good to Know
All the SQL in this tutorial is standard SQL. It runs on MySQL, PostgreSQL, SQLite, and most other databases. Any MySQL-specific syntax will always be clearly labelled.

MySQL Editions

MySQL ships in several editions. For learning — and for the vast majority of web projects — always grab the free Community Edition.

Community Edition
Free, open-source (GPL). Full SQL engine, Workbench, and all connectors. This is what you install.
✓ Recommended
Standard Edition
Paid commercial licence. Adds thread-pooling and enhanced replication. Aimed at small-to-medium production workloads.
Enterprise Edition
Full commercial suite: audit logging, transparent encryption, Oracle 24/7 support. Used by banks, telecoms, and governments.
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.

Windows
The MySQL Installer for Windows bundles the server, Workbench, connectors, and documentation into a single .msi — the easiest path on any platform.
1
Download MySQL Installer
Visit dev.mysql.com/downloads/installer and grab the larger "full" installer — mysql-installer-community-8.x.x.msi (~500 MB). Avoid the small "web" installer; it requires an active internet connection during setup.
2
Run Installer — Choose "Developer Default"
Double-click the .msi. When prompted for Setup Type, choose Developer Default — this installs the MySQL Server, Workbench, Shell, connectors, and documentation in one pass.
3
Configure the Server
Accept Standalone MySQL Server. Keep the default port 3306. For authentication choose Use Strong Password Encryption — this is the correct setting for MySQL 8.
4
Set the Root Password
Choose a strong root password and write it down. You need it every time you connect. You can also add a non-root user for day-to-day work.
Never
Leave the root password blank, even on a local machine. Most modern tools will refuse to connect to an unsecured root account.
5
Finish & Verify
Click Execute to apply the configuration, then Finish. Open Command Prompt and run:
Windows — Command Prompt
# 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
macOS
The easiest macOS path is Homebrew. A .dmg GUI installer is also available at dev.mysql.com/downloads/mysql if you prefer not to use the terminal.
1
Install Homebrew (if not already installed)
Terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2
Install & Start MySQL
Terminal
brew install mysql
brew services start mysql
mysql_secure_installation    # set root password & harden the install
3
Verify the Connection
Terminal
mysql --version
mysql -u root -p
Linux — Ubuntu / Debian
Steps shown for Ubuntu 22.04 / Debian. For RHEL / CentOS / Fedora replace apt with dnf.
1
Update Packages & Install MySQL
Bash
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
2
Create a Named User (Best Practice)
On Ubuntu, root uses socket authentication by default. Create a named user for your day-to-day SQL work:
Bash → MySQL shell
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
Advertisement
📢 Ad space · 728 × 90 · Replace slot ID above
📊
Free Resource
Download our SQL Cheat Sheet
All essential commands, clauses and functions on one printable page.
Get Sheet

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.

MySQL Workbench 8.0 — Local instance 3306
Navigator · Schemas
school_db
students
courses
enrollments
sys
information_schema
-- MySQL Workbench · Query Tab 1
-- 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;
Connect
Open Workbench → click Local instance 3306 → enter your root password. Create a new query tab with Ctrl + T (Mac: Cmd + T).
Run a query
Type SQL in the editor pane. Press Ctrl + Enter to run the statement under the cursor. Results appear in the output panel below.
Schema browser
The left panel lists all databases, tables, views, and stored procedures. Double-click a table name to insert it into your active query automatically.

Verify Your Installation

Run these four commands inside the MySQL shell (or in a Workbench query tab) to confirm everything is working correctly:

SQL — Verification queries
-- 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:

Four system databases present after a clean install
Database
information_schema
mysql
performance_schema
sys
Tip
Never delete or modify 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:

MySQL Component Stack — End to End
Client
Workbench, mysql CLI, your application
↓ TCP connection on port 3306
Connection Manager
Authenticates user & manages threads
↓ SQL parsed, validated, planned
Query Optimiser
Picks the fastest execution plan using indexes
↓ Execution plan sent to storage engine
InnoDB Storage Engine
Reads / writes actual data files on disk
↑ Result set returned to client
Client sees the rows
Displayed in Workbench, app, or terminal
Advertisement
📢 Ad space · 728 × 90 · Replace slot ID above

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.

SQL Query Runner In-Browser
Sample table available: students (id, name, email, city, course, grade)  ·  Try:
Results will appear here after you run a query
Quick Check — Chapter 4

What is the default port that MySQL listens on?

Quick Check — Chapter 4

Which MySQL edition is completely free and open-source?

Quick Check — Chapter 4

On Linux, which command secures a fresh MySQL install by setting the root password and removing anonymous test accounts?

Chapter Summary
  • 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.
Advertisement
📢 Ad space · 728 × 90 · Replace slot ID above

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel