Installing MySQL on macOS
Introduction
On macOS, Homebrew is the most common way to install MySQL 8 for local development. This chapter installs the server, secures the root account, verifies login, and notes the official DMG alternative—so you can run the same SQL examples as on Windows and Linux.
Prerequisites
- What Is MySQL
- macOS 10.15 or later
- Terminal app and admin password
Install with Homebrew (Recommended)
Install Homebrew if needed from brew.sh, then:
brew update
brew install mysqlStart MySQL at login:
brew services start mysqlCheck status:
brew services list | grep mysqlExpected status: started.
Code explanation:
brew servicesmanages launchd—MySQL restarts after reboot when started this way
Secure the Installation
Homebrew MySQL may allow root login without password initially. Run:
mysql_secure_installationTypical answers:
| Prompt | Suggested |
|---|---|
| Validate password component | Your choice (Y for medium strength) |
| Set root password | Yes — choose memorable password |
| Remove anonymous users | Y |
| Disallow root remote login | Y |
| Remove test database | Y |
| Reload privilege tables | Y |
Verify Login
mysql --version
mysql -u root -pAt mysql>:
SELECT VERSION();
SHOW DATABASES;
EXIT;Apple Silicon (M1/M2/M3)
Homebrew on ARM uses /opt/homebrew. Shell integration adds mysql to PATH automatically after install.
If command not found:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"Official DMG Installer (Alternative)
- MySQL Community Downloads — macOS
- Pick ARM64 (Apple Silicon) or x86_64 (Intel)
- Run
.pkginstaller - Use System Settings → MySQL (or legacy preference pane) to start server
Binary location often:
/usr/local/mysql/bin/mysqlAdd to PATH if not linked automatically.
Stop, Upgrade, Remove
brew services stop mysql
brew upgrade mysqlFull removal:
brew services stop mysql
brew uninstall mysql
rm -rf /opt/homebrew/var/mysqlTip
One Server at a Time
If Docker MySQL also maps port 3306, stop one before starting the other.
FAQ
mysql: command not found?
Restart terminal; run brew link mysql or use full path.
Access denied for root?
Run mysql_secure_installation again or reset root per MySQL docs.
MariaDB from brew by mistake?
brew install mysql installs Oracle MySQL—check mysql --version.
Docker instead?
See Installing MySQL with Docker.
JDBC on Mac?
Same server—connect with JDBC macOS install.
Data directory location?
Homebrew: /opt/homebrew/var/mysql (ARM) or /usr/local/var/mysql (Intel).