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 Homebrew if needed from brew.sh, then:

bash
brew update
brew install mysql

Start MySQL at login:

bash
brew services start mysql

Check status:

bash
brew services list | grep mysql

Expected status: started.

Code explanation:

  • brew services manages launchd—MySQL restarts after reboot when started this way

Secure the Installation

Homebrew MySQL may allow root login without password initially. Run:

bash
mysql_secure_installation

Typical answers:

PromptSuggested
Validate password componentYour choice (Y for medium strength)
Set root passwordYes — choose memorable password
Remove anonymous usersY
Disallow root remote loginY
Remove test databaseY
Reload privilege tablesY

Verify Login

bash
mysql --version
mysql -u root -p

At mysql>:

sql
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:

bash
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

Official DMG Installer (Alternative)

  1. MySQL Community Downloads — macOS
  2. Pick ARM64 (Apple Silicon) or x86_64 (Intel)
  3. Run .pkg installer
  4. Use System Settings → MySQL (or legacy preference pane) to start server

Binary location often:

text
/usr/local/mysql/bin/mysql

Add to PATH if not linked automatically.

Stop, Upgrade, Remove

bash
brew services stop mysql
brew upgrade mysql

Full removal:

bash
brew services stop mysql
brew uninstall mysql
rm -rf /opt/homebrew/var/mysql

Tip

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).