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.
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
- Three installation options: Windows, Mac, and Linux
- Quickly Deploy MySQL 8.0 with Docker
- Connecting via the MySQL Workbench graphical client
- Initial Password Setup and Security Configuration
- Configuring Environment Variables and Verifying the Installation
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
# 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 | ⭐⭐⭐ | ⭐ |
3. Docker Installation (Recommended)
(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:
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.
# 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:
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.
mysql>
Output:
Output displayed
▶ Example: Common Docker Management Commands
Output:
mysql-tutorial
mysql-tutorial
mysql-tutorial
# 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:
mysql-tutorial
Output:
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
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
# Open CMD or PowerShell
mysql --version
# Connect MySQL
mysql -u root -p
Output:
mysql Ver 8.0.36 for Win64 on x86_64 (MySQL Community Server - GPL)
5. macOS Installation
▶ Example: Installing Homebrew
Output:
mysql has been installed
Securing the MySQL server deployment.
Welcome to the MySQL monitor. Commands end with ; or \g.
# 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:
==> 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:
Output displayed
6. Linux Installation
▶ Example: Installation on Ubuntu/Debian
Output:
Setting up mysql-server...
Welcome to the MySQL monitor. Commands end with ; or \g.
# 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:
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
-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.-p 3307:3306, and specify mysql -h 127.0.0.1 -P 3307 -u root -p when connecting.mysql command in the command line after installation?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
- Docker is the most recommended installation method; it can be started with a single command
- Windows: Use the official installer and configure it using the graphical wizard
- macOS: We recommend installing it via Homebrew—it's quick and easy.
- Linux: Use the package manager (apt/dnf); you must manually start the service
- MySQL Workbench is the official graphical client, designed for visual operations
- After installation, be sure to change the root password and create a regular user
📝 Exercises
-
Basic Exercise (Difficulty: ⭐): Install MySQL 8.0 using Docker. After successfully connecting, run
SHOW DATABASES;to view the list of default databases. -
Advanced Exercise (Difficulty ⭐⭐): Create a new user named
test_userwith the passwordTestPass123!, grantmydbfull permissions on the database, and verify the connection. -
Challenge (Difficulty: ⭐⭐⭐): Configure MySQL to allow remote connections (by modifying the
bind-address), and successfully connect to it from another machine.