MySQL: A Cross-Platform Guide to Installing and Configuring…

Last updated: 2026-08-26

Installing MySQL is the first step in learning—choosing the right method can save you a lot of trouble.

This lesson covers installation methods for all platforms; we recommend using Docker to get started quickly.

100%
graph TB
    A{Select Installation Method} -->|Recommendations| B[Docker]
    A -->|Windows| C[OfficialInstaller]
    A -->|macOS| D[Homebrew]
    A -->|Linux| E[apt / dnf]
    A -->|Advanced Users| F[Compiling from Source Code]
    B --> G[30Instant Startup]
    C --> H[Graphical Wizard Configuration]
    D --> I[Command-Line Installation]
    E --> J[Package Manager Installation]
    G --> K[Connection Verification]
    H --> K
    I --> K
    J --> K

1. What You'll Learn



2. A True Story of a Beginner

(1) Pain Point: The Installation Process Is a Turn-Off

A front-end developer who wants to learn back-end development starts by installing MySQL:

"I downloaded the official installer, spent 20 minutes installing it on Windows, couldn't figure out the setup wizard, and finally got an error saying 'Service failed to start.' I searched Stack Overflow for ages, but still couldn't get it to work."

This is all too common—installation and configuration are the stages where the highest percentage of beginners give up.

(2) The Docker Solution

BASH
# One-line command, ready in 30 seconds
docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Root123! mysql:8.0

Benefits: Does not clutter the system, starts and stops in seconds, allows for seamless version switching, and uninstalls cleanly without leaving any residue.

Installation Method Time Required Difficulty Recommendation
Docker 1 minute ⭐⭐⭐
Official Installer 15 minutes ⭐⭐ ⭐⭐
Package Manager 5 minutes ⭐⭐ ⭐⭐
Compile from source 30+ minutes ⭐⭐⭐


(1) Install Docker Desktop

Platform Download Link
Windows https://docs.docker.com/desktop/install/windows-install/
Mac (Intel) https://docs.docker.com/desktop/install/mac-install/
Mac (M1/M2) https://docs.docker.com/desktop/install/mac-install/
Linux https://docs.docker.com/engine/install/

▶ Example: Starting MySQL with Docker

Output:

TEXT 📖 Display only
Unable to find image 'mysql:8.0' locally
8.0: Pulling from library/mysql
CONTAINER ID   IMAGE       COMMAND   STATUS   PORTS
Welcome to the MySQL monitor.
BASH
# 1. Pull an image
docker pull mysql:8.0

# 2. Start the container (Set root password to Root123!)
docker run -d \
  --name mysql-tutorial \
  -p 3306:3306 \
  -e MYSQL_ROOT_PASSWORD=Root123! \
  -v mysql_data:/var/lib/mysql \
  mysql:8.0

# 3. View Container Status
docker ps

# 4. Enter MySQL Command Line
docker exec -it mysql-tutorial mysql -u root -pRoot123!

Output:

TEXT 📖 Display only
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.
mysql>

Output:

TEXT 📖 Display only
Output displayed

▶ Example: Common Docker Management Commands

Output:

TEXT 📖 Display only
mysql-tutorial
mysql-tutorial
mysql-tutorial
BASH
# Start a Stopped Container
docker start mysql-tutorial

# Stop the container
docker stop mysql-tutorial

# Restart the container
docker restart mysql-tutorial

# View Logs
docker logs mysql-tutorial

# Delete Container (Must stop first)
docker stop mysql-tutorial && docker rm mysql-tutorial

# Delete Data Volume (Permanently Delete Data)
docker volume rm mysql_data

Output:

TEXT 📖 Display only
mysql-tutorial

Output:

TEXT 📖 Display only
Output displayed


4. Windows Installation

(1) Download the installation package

Visit https://dev.mysql.com/downloads/installer/ to download the MySQL Installer.

▶ Example: Windows Installation Steps

TEXT 📖 Display only
1. Run mysql-installer-community-8.0.x.msi
2. Select "Custom" Installation Type
3. Select MySQL Server 8.0 + MySQL Workbench
4. Layout:
   - Config Type: Development Computer
   - Port: 3306(Default)
   - Authentication Method: Use Strong Password Encryption
   - Root Password: Set a Password (Remember it!)
5. Click Execute Installation Complete

▶ Example: Verifying a Windows Installation

BASH
# Open CMD or PowerShell
mysql --version

# Connect MySQL
mysql -u root -p

Output:

TEXT 📖 Display only
mysql  Ver 8.0.36 for Win64 on x86_64 (MySQL Community Server - GPL)


5. macOS Installation

▶ Example: Installing Homebrew

Output:

TEXT 📖 Display only
mysql has been installed
Securing the MySQL server deployment.
Welcome to the MySQL monitor.  Commands end with ; or \g.
BASH
# 1. Update Homebrew
brew update

# 2. Installation MySQL
brew install mysql

# 3. Start MySQL Services
brew services start mysql

# 4. Secure Initialization
mysql_secure_installation

# 5. Connection Test
mysql -u root -p

Output:

TEXT 📖 Display only
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.36.arm64_sonoma.bottle.tar.gz
==> Pouring mysql-8.0.36.arm64_sonoma.bottle.tar.gz
==> Starting `mysql`...
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

Output:

TEXT 📖 Display only
Output displayed


6. Linux Installation

▶ Example: Installation on Ubuntu/Debian

Output:

TEXT 📖 Display only
Setting up mysql-server...

Welcome to the MySQL monitor.  Commands end with ; or \g.
BASH
# 1. Update Package Index
sudo apt update

# 2. Installation MySQL Server
sudo apt install mysql-server

# 3. Start the service
sudo systemctl start mysql

# 4. Secure Initialization
sudo mysql_secure_installation

# 5. Connection Test
sudo mysql -u root -p

Output:

TEXT 📖 Display only
Output displayed


7. Connecting to MySQL Workbench



8. Security Configuration

(1) Root Password Policy

Strategy Description
Length At least 8 digits
Complexity Includes uppercase and lowercase letters, numbers, and special characters
Avoid using root, 123456, password

❓ FAQ

Q Will data from MySQL installed via Docker be lost?
A If you use a -v mysql_data:/var/lib/mysql data volume, the data will be persisted. If you don't use a data volume, the data will be lost when you delete the container.
Q What should I do if port 3306 is in use?
A Switch to a different port: -p 3307:3306, and specify mysql -h 127.0.0.1 -P 3307 -u root -p when connecting.
Q What should I do if I forget the root password?
A If you're using Docker, simply delete the container and recreate it. For other methods, you'll need to bypass the authentication process to reset the password. For specific steps, search for "MySQL reset root password."
Q Should I choose MySQL 5.7 or 8.0?
A Choose 8.0 for new projects (supports window functions and JSON enhancements). Use 5.7 for maintaining legacy projects. The two versions are 95% syntax-compatible.
Q Can't find the mysql command in the command line after installation?
A You need to add the MySQL bin directory to the PATH environment variable. Windows: System Properties → Environment Variables → Path → Add C:\Program Files\MySQL\MySQL Server 8.0\bin. Mac/Linux: export PATH=$PATH:/usr/local/mysql/bin.

📖 Summary


📝 Exercises

  1. Basic Exercise (Difficulty: ⭐): Install MySQL 8.0 using Docker. After successfully connecting, run SHOW DATABASES; to view the list of default databases.

  2. Advanced Exercise (Difficulty ⭐⭐): Create a new user named test_user with the password TestPass123!, grant mydb full permissions on the database, and verify the connection.

  3. Challenge (Difficulty: ⭐⭐⭐): Configure MySQL to allow remote connections (by modifying the bind-address), and successfully connect to it from another machine.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏