This guide provides a comprehensive walkthrough for installing MySQL on macOS, catering to developers, database administrators, and anyone looking to leverage the power of this open-source relational database management system on their Apple hardware. We will explore different installation methods, from the official installer to popular package managers, ensuring a smooth and efficient setup process.
Understanding MySQL and Its Relevance for macOS Users
MySQL is a robust, widely-used relational database system that underpins a vast array of web applications, backend services, and data-driven projects. Its reliability, performance, and open-source nature have made it a go-to choice for developers across various platforms, including macOS. For macOS users, integrating MySQL locally offers a powerful environment for development, testing, and local data management without the complexities of remote server configurations. Whether you are building a new web application, learning database concepts, or migrating existing projects, a local MySQL installation on your Mac is an invaluable asset.

The flexibility of macOS, combined with the power of MySQL, creates a potent development ecosystem. Developers can seamlessly switch between native macOS applications and command-line tools, all while having their database readily accessible. This guide will empower you to set up your MySQL environment efficiently, enabling you to focus on building and innovating.
Why Install MySQL Locally on macOS?
- Development and Testing: The most common reason for local installation is to provide a dedicated environment for developing and testing applications. This allows for rapid iteration and debugging without affecting live production databases.
- Learning and Education: For students and aspiring developers, a local MySQL instance is essential for understanding database concepts, practicing SQL queries, and building foundational knowledge.
- Data Management: Even for non-developers, a local MySQL database can be used for personal data organization, project management, or small-scale data analysis.
- Performance: Running a database locally can offer superior performance for certain development tasks compared to accessing a remote server, especially with high latency.
- Offline Accessibility: Your database remains accessible even without an internet connection, crucial for uninterrupted development workflows.
- Cost-Effectiveness: While cloud-based database solutions exist, a local installation is free and eliminates ongoing hosting costs for development environments.
Key Components of a MySQL Installation
Before diving into the installation steps, it’s beneficial to understand the core components you’ll be working with:
- MySQL Server: This is the core database engine that stores, manages, and retrieves data. It runs as a background process on your Mac.
- MySQL Client: This is the tool used to interact with the MySQL server. This can be a command-line interface (CLI) or a graphical user interface (GUI) application.
- Configuration Files: These files control the behavior and settings of the MySQL server, such as port numbers, memory allocation, and security parameters.
- Data Directory: This is the location on your file system where MySQL stores its database files.
Method 1: Installing MySQL Using the Official macOS Installer
The most straightforward and recommended method for many users is to download and install MySQL directly from the official Oracle website. This method provides the latest stable versions and includes a graphical installer for ease of use.
Step 1: Download the MySQL Community Server Installer
- Navigate to the official MySQL Downloads page: https://dev.mysql.com/downloads/mysql/
- Select “macOS” as the operating system.
- Choose the “DMG Archive” download type.
- You will see a list of available macOS packages. Look for the latest stable version of “MySQL Community Server.” It’s generally recommended to select the “macOS x86_64” or “macOS ARM” package depending on your Mac’s processor (Intel or Apple Silicon).
- Click the “Download” button. You might be prompted to log in or sign up for an Oracle Web account, but you can skip this by clicking the “No thanks, just start my download.” link at the bottom of the page.
Step 2: Run the Installer Package
- Once the
dmgfile has finished downloading, locate it in your Downloads folder and double-click it to mount the disk image. - Inside the mounted disk image, you will find a
.pkginstaller file. Double-click this file to launch the MySQL installer. - Follow the on-screen prompts. You will need to agree to the software license agreement and select an installation destination (usually your primary hard drive).
- During the installation process, you will be asked to set a root password. This is a critical step. Choose a strong, memorable password and make sure to record it securely. You will need this password to administer your MySQL server.
- The installer will then proceed to copy the necessary files to your system. This may take a few minutes.
- Upon completion, the installer will typically inform you that the installation was successful and may offer options to start the MySQL server automatically or configure it.
Step 3: Starting and Verifying the MySQL Server
- After the installation, macOS will usually prompt you to configure the server. You might see a “System Preferences” pane or a notification asking to configure MySQL.
- Open “System Preferences” (or “System Settings” on newer macOS versions) and look for the “MySQL” icon. Click on it.
- In the MySQL preference pane, you will see options to start or stop the MySQL server. Click “Start MySQL Server” if it’s not already running.
- To verify that the server is running, you can open the “Terminal” application (found in Applications > Utilities).
- Type the following command and press Enter:
bash
mysql -u root -p
- You will be prompted to enter the root password you set during installation. Type it in (you won’t see characters as you type) and press Enter.
- If the connection is successful, you will see the MySQL command-line prompt, which looks like this:
mysql>
- To exit the MySQL prompt, type
exitand press Enter.
Step 4: Installing MySQL Workbench (Optional but Recommended)
MySQL Workbench is a powerful graphical tool that simplifies database design, development, and administration. It’s highly recommended for managing your MySQL databases visually.
- Go back to the MySQL Downloads page: https://dev.mysql.com/downloads/workbench/
- Select “macOS” as the operating system.
- Download the macOS version (typically a
.dmgfile). - Open the downloaded
dmgfile and drag the MySQL Workbench application icon to your Applications folder. - Launch MySQL Workbench from your Applications folder.
- You can create a new connection to your local MySQL server. For the connection details, use:
- Hostname:
127.0.0.1(orlocalhost) - Port:
3306(default MySQL port) - Username:
root - Password: The root password you set during installation.
- Hostname:
MySQL Workbench provides an intuitive interface for creating databases, tables, executing SQL queries, managing users, and monitoring server performance.
Method 2: Installing MySQL Using Homebrew
Homebrew is a popular package manager for macOS that simplifies the installation and management of software. If you are already using Homebrew, this method offers a command-line driven approach that integrates well with other development tools.
Step 1: Install Homebrew (If Not Already Installed)
If you don’t have Homebrew installed, open your Terminal application and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions to complete the installation. It may involve entering your macOS user password.
Step 2: Install MySQL using Homebrew
Once Homebrew is installed, you can install MySQL with a single command in your Terminal:
brew install mysql
Homebrew will download and install the latest version of MySQL, along with any necessary dependencies. This process can take several minutes depending on your internet connection.
Step 3: Starting and Verifying the MySQL Server
After the Homebrew installation is complete, it will provide instructions on how to start the MySQL server. Typically, you’ll need to run:
mysql.server start
To verify that the server is running, you can use the same command as in Method 1:
mysql -u root -p
You will be prompted for a password. Important: When installing with Homebrew, a root password is not automatically set by default. The first time you connect, you might be able to connect without a password, or you might be prompted to set one up as part of a security script.
Step 4: Securing Your MySQL Installation (Homebrew Specific)
Homebrew’s MySQL installation usually requires a post-installation security script to be run. This script helps set up the root password, remove anonymous users, disallow root login remotely, and remove the test database.
- Run the security script:
bash
mysql_secure_installation
- Follow the prompts carefully. You will be asked to set a root password, validate password component, remove anonymous users, disallow root login remotely, remove test database, and reload privilege tables.
- When prompted for the current password for root, if you haven’t set one, just press Enter.
- When prompted to set a new root password, choose a strong one and confirm it.
Step 5: Enabling Automatic Startup (Optional)
To have MySQL start automatically when your Mac boots up, you can use the following command:
brew services start mysql
To stop the service:

brew services stop mysql
To check the status:
brew services list
Method 3: Using Docker for MySQL
Docker provides an isolated, containerized environment for running applications, including databases. This is an excellent option for developers who want to manage multiple database versions or ensure consistent environments across different machines.
Step 1: Install Docker Desktop for Mac
- Download Docker Desktop for Mac from the official Docker website: https://www.docker.com/products/docker-desktop/
- Run the downloaded
.dmgfile and drag the Docker icon to your Applications folder. - Launch Docker Desktop from your Applications folder. You will likely need to grant it permissions and complete a brief setup process.
Step 2: Pull the MySQL Docker Image
Open your Terminal and pull the official MySQL Docker image:
docker pull mysql
This command downloads the latest official MySQL image from Docker Hub.
Step 3: Run a MySQL Container
To run a MySQL container, you’ll use the docker run command. Here’s a common example that starts a MySQL server, exposes its port, and sets a root password:
docker run --name my-mysql-container -e MYSQL_ROOT_PASSWORD=your_strong_password -d -p 3306:3306 mysql
Let’s break down this command:
docker run: The command to create and start a new container.--name my-mysql-container: Assigns a name to your container for easy reference.-e MYSQL_ROOT_PASSWORD=your_strong_password: Sets the root password for the MySQL server. Replaceyour_strong_passwordwith a secure password.-d: Runs the container in detached mode (in the background).-p 3306:3306: Maps port 3306 on your Mac to port 3306 inside the container. This allows you to connect to MySQL from your Mac as if it were running locally.mysql: The name of the Docker image to use.
Step 4: Connecting to the MySQL Container
You can connect to your MySQL container using the MySQL client on your Mac (if installed) or through MySQL Workbench.
Using Terminal:
mysql -h 127.0.0.1 -P 3306 -u root -p
You will be prompted for the your_strong_password you set when running the docker run command.
Using MySQL Workbench:
Create a new connection with:
- Hostname:
127.0.0.1 - Port:
3306 - Username:
root - Password: The password you set in the
docker runcommand.
Step 5: Managing Your Docker Container
- View running containers:
docker ps - Stop the container:
docker stop my-mysql-container - Start the container:
docker start my-mysql-container - Remove the container (and all its data):
docker rm my-mysql-container
Important Note on Data Persistence: By default, data within a Docker container is ephemeral. To persist your MySQL data even if the container is removed, you should use Docker volumes. For example:
docker run --name my-mysql-container
-e MYSQL_ROOT_PASSWORD=your_strong_password
-v mysql_data:/var/lib/mysql
-d -p 3306:3306
mysql
Here, -v mysql_data:/var/lib/mysql creates a named volume mysql_data on your Mac and mounts it to the MySQL data directory inside the container, ensuring data persistence.
Post-Installation: Best Practices and Common Tasks
Once MySQL is installed, it’s good practice to be aware of a few essential tasks and recommendations to ensure a secure and efficient database environment.
Managing the MySQL Service
- Using
mysql.server(Official Installer):- Start:
sudo /usr/local/mysql/support-files/mysql.server start - Stop:
sudo /usr/local/mysql/support-files/mysql.server stop - Restart:
sudo /usr/local/mysql/support-files/mysql.server restart
- Start:
- Using
brew services(Homebrew):- Start:
brew services start mysql - Stop:
brew services stop mysql - Restart:
brew services restart mysql
- Start:
Connecting to MySQL from the Terminal
The command to connect to your MySQL server from the Terminal is:
mysql -u username -p
Replace username with the MySQL user you want to connect as (e.g., root). You will be prompted to enter the password for that user.
Creating New Databases and Users
After connecting as the root user, you can manage your databases:
- Create a new database:
sql
CREATE DATABASE my_new_database;
- Create a new user:
sql
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'a_secure_password';
- Grant privileges to the new user:
sql
GRANT ALL PRIVILEGES ON my_new_database.* TO 'new_user'@'localhost';
- Apply privilege changes:
sql
FLUSH PRIVILEGES;
Understanding Configuration Files
The primary configuration file for MySQL on macOS is typically my.cnf. Its location can vary depending on the installation method:
- Official Installer: Often found in
/etc/my.cnfor/usr/local/mysql/my.cnf. - Homebrew: Usually located at
/usr/local/etc/my.cnf.
You can edit this file to tune MySQL’s performance, security, and other settings. After making changes, you will need to restart the MySQL server for them to take effect.

Regular Maintenance
- Backups: Regularly back up your databases using tools like
mysqldumpor MySQL Workbench. - Updates: Keep your MySQL installation updated to benefit from security patches and new features. For Homebrew, this is as simple as
brew updateandbrew upgrade mysql. For the official installer, you’ll need to download and run newer versions.
By following this comprehensive guide, you should now have a functional MySQL installation on your macOS system, ready for your development and data management needs. Whether you prefer the simplicity of the official installer, the efficiency of Homebrew, or the isolation of Docker, there’s a method that fits your workflow.
