How to Install & Set Up MySQL

MySQL is the heart of data-driven applications — but before you can build powerful web apps or dashboards, you need to install and set it up correctly. This guide will walk you through how to install MySQL on Windows, macOS, and Linux with screenshots, tips, and best practices.
What You’ll Learn
How to install MySQL on Windows, macOS, and Linux
Setting up MySQL Workbench for GUI access
Using the MySQL Command-Line Tool
Verifying the installation and basic connection steps
📥 Installing MySQL on Windows
✅ Step 1: Download the Installer
Go to the official MySQL website:
👉 https://dev.mysql.com/downloads/installer/
Choose:
- MySQL Installer for Windows
- Either the web installer (smaller size) or the full installer
✅ Step 2: Run the Installer
Launch the .msi
file and follow these options:
- Choose Developer Default (includes MySQL Server, Workbench, Shell, and more)
- Installer will automatically download and configure dependencies
✅ Step 3: Configure MySQL Server
During setup:
- Set a root password
- Select the port (default: 3306)
- Choose Standalone MySQL Server configuration
💡 Note: Save your root password securely — you’ll need it to access MySQL later.
✅ Step 4: Finish and Launch MySQL Workbench
Once installation is complete:
- Launch MySQL Workbench
- Connect using your root credentials
🍎 Installing MySQL on macOS
✅ Option 1: Using Homebrew (Recommended)
brew update
brew install mysql
brew services start mysql
After installation, run:
mysql_secure_installation
ollow the prompts to set a root password and configure security options.
✅ Option 2: Download the DMG Installer
Download from:
👉 https://dev.mysql.com/downloads/mysql/
Install via the .dmg
file:
- Includes MySQL server, Startup item, and Preference pane
- Use System Preferences to manage MySQL service
🐧 Installing MySQL on Linux (Ubuntu/Debian)
sudo apt update
sudo apt install mysql-server
After installation, run:
sudo mysql_secure_installation
Then start the MySQL service:
sudo systemctl start mysql
sudo systemctl enable mysql
To access the MySQL shell:
sudo mysql -u root -p
🖥️ MySQL Workbench: GUI for Visual SQL
MySQL Workbench is a powerful GUI tool for:
- Writing and executing queries
- Visual database design (ER diagrams)
- User management
- Export/import of data
Download it here:
👉 https://dev.mysql.com/downloads/workbench/
⚠️ If you’re a beginner, MySQL Workbench can greatly simplify learning and managing databases.
🧪 Testing Your Installation
Once MySQL is installed, test it:
✔️ From Terminal/Command Line
mysql -u root -p
You should see:
Welcome to the MySQL monitor. Commands end with ; or \g.
✔️ Check MySQL Version
SELECT VERSION();
Sample Output:
+-----------+
| version |
+-----------+
| 8.0.34 |
+-----------+
🔐 Common Setup Pitfalls
Problem | Solution |
---|---|
Forgot root password | Reset using mysqld --skip-grant-tables |
Port 3306 is in use | Change port during setup or close conflicting services |
Can’t connect via Workbench | Check firewall settings and ensure MySQL service is running |
💡 Pro Tips
- Always use
mysql_secure_installation
after installation for security hardening. - Use MySQL Shell (
mysqlsh
) for modern JSON-based or NoSQL-style queries. - Install phpMyAdmin for a browser-based admin tool (if you’re using PHP stack).