How to install MySQL on macOS

Although Windows is the main platform to consider when it comes to database development and management, what if you have a Mac and would like to start your endeavors from there? Well, challenge accepted. Here is the guide that will help you set up a MySQL environment on macOS.

About MySQL

MySQL is a name that's just as big in the sphere of data and relational databases. It is often called the most popular open-source database management system, and it sees effective use in nearly any industry. Based on Structured Query Language (SQL), it delivers a well-balanced combination of performance, convenience, and security. When it comes to compatibility with macOS, MySQL 8.0 is the version of your choice.

The main features of MySQL

  • High performance
  • On-demand scalability
  • Data security
  • Support for large databases
  • Support for multiple data types and character sets

About macOS

macOS is a proprietary operating system developed and marketed by Apple Inc. It is the second most widely used desktop OS in the world (after Microsoft Windows, of course), the standard OS for Apple's renowned Mac computers, and one of the most popular platforms for developers. MySQL currently supports macOS 11 (Big Sur) and macOS 12 (Monterey).

What are the prerequisites for installing MySQL on a Mac?

You have two options: you can either download MySQL from the official website or use Terminal. You will find guides to both of these options below. In order to begin, you should have macOS 11 or 12 on your machine, and you need to install MySQL 8.0 to ensure full compatibility. Other than that, there are no specific prerequisites.

Download the latest version of MySQL for Mac

You can download MySQL for Mac from the official MySQL website. Since there are many options, the following guide might come in handy and help you find what you need faster.

In the header of the MySQL website, go to the Downloads tab.
Scroll down and select MySQL Community (GPL) Downloads.
Select MySQL Community Server.
In the Select Operating System dropdown menu, select macOS.
Find the required processor version and select Download.
Then you will be prompted to either sign up or log in to your Oracle Web account. Just below the buttons, select No thanks, just start my download. The download will commence.

How to install MySQL on macOS

After MySQL is downloaded, you can proceed to the installation process.

Double-click the downloaded DMG file to open a wizard-like installer. It will tell you it has to determine if the software it contains can be installed. Click Allow. Then you will see links to MySQL-related resources, including the documentation. Click Continue.
On the License page, accept the Software License Agreement by clicking Continue.
Next, you need to choose the download destination. By default, it's your main hard drive. If you want to change it, click Change Install Location. If you don't, click Install.
Enter your password, click Install Software, and wait while the files get installed on your Mac.
On the Configuration page, select Use Strong Password Encryption. Click Next. Enter your MySQL root password, click Finish, and the installation will be complete.

How to download and install MySQL Server using Homebrew and Terminal

Alternatively, you can use the Homebrew package manager to download and install MySQL on your Mac from Terminal, the stock CLI available in macOS.

1. If you haven't previously installed Homebrew on your Mac, open Terminal and execute the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After this command is executed, you will have commands such as brew install, brew upgrade, and brew uninstall available from Terminal.

2. And so, in order to install MySQL, you need to run the following command:

brew install mysql

3. The installation will take a while. After it's finished, you can start your MySQL server with the following command:

brew services start mysql

4. To secure your MySQL with a root password, run the following:

mysql_secure_installation

How to configure MySQL from the command line

MySQL can be further configured from Terminal. For instance, it allows you to manage users. To create a new database user from Terminal and grant all privileges on all databases, enter the following command, replace "username" with the user you want to create, and replace "password" with the user's password.

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost'
IDENTIFIED BY 'password';

You may also need to grant specific permissions. For instance, use the following command to explicitly grant the SELECT permission to the user.

GRANT SELECT ON *.* TO 'username'@'localhost'

If you want to narrow down user access to a specific database, enter the following command and replace "database" with the name of your database.

GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';

To enable remote access to MySQL, we suggest creating a user with access from a specific IP address ('username'@'192.168.1.100') or from any host ('username'@'%').

How to start MySQL on macOS

Like we said previously, you can start MySQL in Terminal by running brew services start mysql. Similarly, you can stop MySQL by running brew services stop mysql and restart it via brew services restart mysql. Alternatively, you can easily start and stop MySQL server instances on your Mac from System Preferences > MySQL.

There, you can also choose whether you want to run the server automatically on startup, click Initialize Database to configure your default MySQL database, or go to the Configuration tab to select the configuration file (if required) and specify paths to base, data, and plugin directories, as well as paths to the keyring data file, PID file, and error log.

How to update MySQL on macOS

The easiest way to update your MySQL is to run brew upgrade mysql in Terminal.

Note that in this case, a manual update is far less convenient - it means that you will have to uninstall your current MySQL and then install a new version from scratch.

Need a reliable solution
to manage your MySQL databases?

Get the most advanced IDE on the market - dbForge Studio for MySQL

Manage MySQL Server using a client or an IDE

The most productive and convenient way to manage MySQL databases is to use a specialized IDE. The most common choice is the free yet functionally limited Community Edition of MySQL Workbench. But if you need to cover a wider range of tasks, you can try a more sophisticated solution like dbForge Studio for MySQL, which is designed to cover and streamline your routine database development and management.

With dbForge Studio, you can design databases and develop them, copy databases for migration, manage users, compare and synchronize databases, analyze table data, and much more. You can run the Studio on your Mac via CrossOver, a commercial compatibility solution that allows running Windows software on macOS and Linux. To learn how to do it, refer to our product documentation.

Database Design

dbForge Studio for MySQL offers tools that help you instantly create database diagrams, objects, and entire projects, as well as efficiently compare and sync database schemas and table data.

Make database migration faster
2X
Saved time

Database Development

You can write, debug, and run SQL queries faster using the built-in code completion and formatting tools, as well as measure and optimize query performance in a matter of moments.

Make database migration faster
2X
Faster coding speed

Database Management

An integrated set of database management tools help import and export table data, migrate, compare, and synchronize databases, as well as generate meaningful data for effective testing.

Make database migration faster
16X
Faster database migration

Database Administration

With the help of dbForge Studio, you can manage accounts, set up permissions, monitor open sessions and their activity, as well as perform table maintenance. In addition, it is possible to back up and restore databases to/from your backup files.

Make database migration faster
+40%
Daily performance

Data Analysis and Reporting

dbForge Studio makes data analysis and reporting far less time-consuming with a slew of auxiliary tools.

Make database migration faster
300%
Efficiency boost

How to uninstall MySQL Server from a Mac

In Terminal, you can easily uninstall MySQL by running brew uninstall mysql

Alternatively, you can uninstall the required MySQL server instance on your Mac from System Preferences > MySQL.