Installing MySQL 8.0 on macOS with Homebrew: A Complete Guide
Introduction
Recently, I needed to set up a development environment on my Mac and chose to use Homebrew to install MySQL 8.0. The process was smoother than expected, so I'm sharing the complete installation steps and some practical tips here.
Prerequisites
Make sure Homebrew is already installed on your system. If not, run this command in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Installation Steps
1. Update Homebrew
First, update Homebrew to the latest version:
brew update
2. Install MySQL 8.0
Run the following command to install MySQL 8.0:
brew install mysql@8.0
The installation process will automatically download and configure MySQL, usually taking a few minutes. Homebrew automatically handles environment variable configuration, so you can use the mysql command directly after installation.
3. Start MySQL Service
There are two ways to start the MySQL service:
Option 1: Start immediately (without auto-start on boot)
brew services start mysql@8.0
Option 2: Manual start
mysql.server start
4. Security Configuration
Run MySQL's security configuration script:
mysql_secure_installation
This script will guide you through the following configurations:
- Set root password
- Remove anonymous users
- Disallow root login remotely
- Remove test database
- Reload privilege tables
It's recommended to select "Yes" for all options to enhance security.
Verify Installation
Log into MySQL
Enter the password you just set to log in.
mysql -u root -p
Option: DataGrip config
If you prefer to operate the database using a GUI tool, you can configure the DataGrip connect MySQL.
Common Commands
Service Management
# Start service
brew services start mysql@8.0
# Stop service
brew services stop mysql@8.0
# Restart service
brew services restart mysql@8.0
# Check service status
brew services list
Connect to MySQL
# Connect as root user
mysql -u root -p
# Connect to specific database
mysql -u root -p database_name
# Specify host and port
mysql -h localhost -P 3306 -u root -p
Uninstalling MySQL
If you need to uninstall:
# Stop service
brew services stop mysql@8.0
# Uninstall
brew uninstall mysql@8.0
# Delete data (optional)
rm -rf /opt/homebrew/var/mysql
Conclusion
Installing MySQL 8.0 with Homebrew is very straightforward - the entire process requires just a few commands. Homebrew automatically handles dependencies and configuration, making it much easier than manual installation. Remember to complete the security configuration after installation, and you're ready to start using MySQL!
I hope this tutorial helps! Feel free to share in the comments if you encounter any other issues.





Top comments (0)