How to Install MySQL on Windows, macOS & Linux — Step-by-Step 2026

Sanjeev SharmaSanjeev Sharma
6 min read

Advertisement

Introduction

Why This Matters

MySQL is the world's most widely deployed open-source relational database. It powers WordPress, GitHub, Airbnb, Twitter, and countless other applications. Before you can practice SQL queries, build a web application with a database backend, or run any MySQL tutorial, you need a working installation.

This guide walks through installation on all three major operating systems, explains each configuration step, and shows you how to verify the setup is working correctly. By the end you will have MySQL running locally and know how to connect to it.

System Requirements (2026)

ComponentMinimumRecommended
RAM4 GB8 GB
Disk5 GB free20 GB free
OS (Windows)Windows 10 64-bitWindows 11
OS (macOS)macOS 12 MontereymacOS 14 Sonoma
OS (Linux)Ubuntu 20.04 / CentOS 7Ubuntu 22.04 / Rocky Linux 9
MySQL Version8.08.4 LTS

Installing MySQL on Windows

Step 1 — Download the Installer

Go to mysql.com/downloads and download the MySQL Installer for Windows. Choose the larger offline installer (mysql-installer-community-x.x.x.msi) for reliable installation without an internet dependency.

Step 2 — Run the MSI Installer

Double-click the downloaded .msi file. When prompted for Setup Type, choose:

  • Developer Default — installs MySQL Server, MySQL Workbench, MySQL Shell, connectors, and sample databases. Best for learning and development.
  • Server Only — installs only the database server. Best for production servers.

Step 3 — Resolve Missing Requirements

The installer will flag missing prerequisites such as Microsoft Visual C++ Redistributable. Click Execute to let the installer download and install them automatically.

Step 4 — Choose Server Configuration Type

When the MySQL Server configuration wizard appears:

  • Config Type: Development Computer (uses fewer resources)
  • Connectivity: TCP/IP, Port 3306 (the MySQL default)
  • Named Pipe / Shared Memory: leave unchecked unless required

Step 5 — Select Authentication Method

Choose Use Strong Password Encryption (Recommended). This uses the caching_sha2_password plugin introduced in MySQL 8.0. If you must connect older clients that do not support it, choose the legacy option.

Step 6 — Set the Root Password

Enter a strong root password (at least 12 characters, mixed case, numbers, and symbols). Store it in a password manager — you cannot recover it without resetting.

Optionally add additional MySQL user accounts at this step.

Step 7 — Configure Windows Service

Keep Start the MySQL Server at System Startup checked for development machines. Set the service name to MySQL80 (the installer default). Click Next, then Execute to apply the configuration.

Step 8 — Complete Installation

Click Finish in the configuration wizard, then Next and Finish in the main installer. MySQL Workbench may launch automatically.

Installing MySQL on macOS

The fastest method on macOS is Homebrew:

# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
 
# Install MySQL
brew install mysql
 
# Start MySQL as a background service
brew services start mysql
 
# Secure the installation (set root password, remove test databases)
mysql_secure_installation

Follow the prompts in mysql_secure_installation. Answer Y to all questions for a secure setup.

Alternatively, download the macOS .dmg package from mysql.com and follow a GUI wizard similar to the Windows installer.

Installing MySQL on Linux (Ubuntu / Debian)

# Update package list
sudo apt update
 
# Install MySQL Server
sudo apt install mysql-server -y
 
# Start and enable the service
sudo systemctl start mysql
sudo systemctl enable mysql
 
# Run the security script
sudo mysql_secure_installation

For Red Hat / CentOS / Rocky Linux:

sudo dnf install mysql-server -y
sudo systemctl start mysqld
sudo systemctl enable mysqld
 
# Get the temporary root password from the log
sudo grep 'temporary password' /var/log/mysqld.log
 
# Log in and change the password
mysql -u root -p

Verifying the Installation

After installation on any platform, open a terminal or the MySQL Command Line Client and connect:

mysql -u root -p

Enter your root password when prompted. You should see the mysql> prompt. Run these commands to confirm everything is working:

-- Show all databases (system databases should appear)
SHOW DATABASES;
 
-- Check the MySQL version
SELECT VERSION();
 
-- Exit
EXIT;

Expected output for SHOW DATABASES:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Post-Installation: Create a Non-Root User

Running applications as the root user is a security risk. Create a dedicated user:

-- Create user with password
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
 
-- Grant privileges on a specific database
GRANT ALL PRIVILEGES ON school_mgmt.* TO 'appuser'@'localhost';
 
-- Apply the changes
FLUSH PRIVILEGES;

Common Mistakes

  • Forgetting the root password. Write it down or store it in a password manager immediately.
  • Port 3306 already in use. Another MySQL instance or a service like MariaDB may be running. Change the port or stop the conflicting service.
  • Firewall blocking connections. On Linux, ensure port 3306 is allowed: sudo ufw allow 3306.
  • Not running mysql_secure_installation. This leaves anonymous users and test databases that are security vulnerabilities.
  • Installing as root on Linux without sudo. Always prefix MySQL service commands with sudo.

Best Practices

  • Always run mysql_secure_installation immediately after installation to remove insecure defaults.
  • Create a non-root application user and grant only the privileges that user needs.
  • Enable the MySQL general query log during development to inspect all queries: SET GLOBAL general_log = 'ON';
  • Use MySQL Workbench or DBeaver as a GUI client for visual schema exploration and query editing.
  • Keep MySQL updated to the latest patch release within your major version to receive security fixes.
  • Back up databases regularly with mysqldump or MySQL Enterprise Backup.

Key Takeaways

  • MySQL 8.4 LTS is the recommended version in 2026; it includes improved security defaults and performance enhancements over 5.7.
  • On Windows, use the MySQL Installer (MSI) to install MySQL Server, Workbench, and Shell in one step.
  • On macOS, brew install mysql followed by brew services start mysql is the quickest setup path.
  • On Ubuntu/Debian, sudo apt install mysql-server installs MySQL; always follow with mysql_secure_installation.
  • The default MySQL port is 3306; verify no other service occupies it before installation.
  • mysql_secure_installation removes anonymous users, test databases, and remote root login — run it on every installation.
  • Never use the root account for application database connections; create a least-privilege application user instead.
  • SHOW DATABASES and SELECT VERSION() are the quickest commands to verify a working MySQL installation.

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro

Related reading