Content Index
- Why install MySQL on Mac using Homebrew
- Prerequisites before installing MySQL on macOS
- How to install MySQL on macOS with Homebrew
- Install Homebrew on Mac (if you don't have it)
- Install MySQL with brew install mysql
- Step 1: Install MySQL with Brew
- How to start and check the MySQL service on Mac
- Basic MySQL configuration after installation
- Access MySQL as root
- Secure installation with mysql_secure_installation
- Create MySQL users on macOS (local and remote)
- Create local user
- Create user with remote access
- Allow remote connections to MySQL on Mac
- Edit my.cnf
- Connect MySQL with graphical tools (GUI)
- Using Sequel Pro
- Common Error: caching_sha2_password
- TablePlus
- FAQs about MySQL on macOS with Homebrew
- Conclusion
MySQL is an open-source database management system. It is used to implement databases. For any website or any other application, there must be some required database. This database is a type of server.
You can implement a database and connect it to the server. It will help extract data from the database using queries. It is the same operation we do in the SQL query language. We can add, access, and format data in the MySQL table.
Feature:
- It is open-source and easy to download and install.
- It is a very fast database language.
- Implementing a database and using it is very simple.
- It can be installed on any operating system.
There are several ways to install MySQL on macOS; here we bring you two with their respective videos. You can install it using the installer that you can download from the official website, although the most recommended way is to use a package manager like Homebrew, which is what we are going to explain in this post.
We are going to learn how to install MySQL manually on a Mac using Homebrew, which will be a fairly simple process with just a few commands; these steps work whether you use a Mac with Intel or M1.
Installing MySQL on macOS might seem complicated the first time, but using Homebrew the process is fast, clean, and easy to maintain. After several installations on both Intel Macs and Apple Silicon (M1/M2), this is the way that has given me the best results for having MySQL running without headaches.
In this guide, I explain how to install MySQL on macOS with Homebrew, how to configure it correctly, and how to avoid the most common errors when connecting from graphical tools like Sequel Pro or TablePlus.
Why install MySQL on Mac using Homebrew
Although you can download MySQL from the official website, in practice Homebrew is the most recommended option if you work as a developer.
Clear advantages:
- Installation and updates with a single command
- Compatible with modern macOS (Intel and Apple Silicon)
- Better integration with the Terminal
- Fewer version conflicts
After trying both methods, Homebrew has always given me fewer problems in the long run, especially when it comes to updating MySQL or reinstalling it.
Prerequisites before installing MySQL on macOS
Before starting, make sure you meet these:
- Updated macOS
- Access to the Terminal
- Administrator permissions on your Mac
You don't need anything else. Homebrew will take care of the rest.
How to install MySQL on macOS with Homebrew
Install Homebrew on Mac (if you don't have it)
If you don't have Homebrew installed yet, open the Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Upon completion, you will have commands like brew install, brew upgrade, and brew uninstall available.
Install MySQL with brew install mysql
After installing Homebrew, open your terminal and you should run the following commands:
Step 1: Install MySQL with Brew
$ brew install mysqlThis command downloads and installs the stable version of MySQL along with everything needed to run it on macOS. On M1 and M5 Macs, it works exactly the same.
With this service, we install MySQL with brew; just like that, now we have to start the service:
 5.10.11 p. m..png)
How to start and check the MySQL service on Mac
Once installed, you must start the service:
$ brew services start mysqlTo verify that MySQL is working correctly:
$ mysql --versionAnd to connect to the server:
$ mysql -u rootIn many initial installations, MySQL allows root access without a password using localhost. This is convenient, but it's not the most secure way.
Basic MySQL configuration after installation
Access MySQL as root
You can enter the MySQL client with:
$ mysql -u rootOr, if you already configured a password:
$ mysql -u root -pThis is where the real configuration begins.
Secure installation with mysql_secure_installation
We have two ways of configuration; the first, the simplest one, would work for you in most cases:
Step 1: Go through the MySQL secure installation workflow
$ mysql_secure_installationthen enter your password
- password: <insert your password>
This wizard allows you to:
- Set password for root
- Remove anonymous users
- Disable remote root login
- Remove test databases
This step avoids many security problems and weird behaviors later on.
Create MySQL users on macOS (local and remote)
Create local user
Instead of always working with root, it is most recommended to create your own user:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'userpassword';
GRANT ALL ON *.* TO 'user'@'localhost';
FLUSH PRIVILEGES;This is sufficient for most local development environments.
Create user with remote access
If you need to connect from another machine or container, create a remote user:
CREATE USER 'user'@'%' IDENTIFIED BY 'yourpassword';
GRANT ALL ON *.* TO 'user'@'%';
FLUSH PRIVILEGES;This step is usually the most forgotten and causes connection errors.
Allow remote connections to MySQL on Mac
In addition to the remote user, you need to edit the configuration file:
$ sudo nano /usr/local/etc/my.cnfMake sure you have these lines:
bind-address = 0.0.0.0
mysqlx-bind-address = 127.0.0.1Save the changes and restart MySQL:
$ brew services restart mysqlWhen I tested remote access for the first time, until I restarted the service, MySQL kept ignoring the new configuration.
Edit my.cnf
sudo nano /usr/local/etc/my.cnf
Editar bind-address a 0.0.0.0
bind-address = 0.0.0.0
mysqlx-bind-address = 127.0.0.1Try to log in with your user and test remote communication with your IP address. In case it doesn't work, restart your PC.
Connect MySQL with graphical tools (GUI)
Using Sequel Pro
You might get an error like the following when trying to connect to your database from your database management system; for example, Sequel Pro:
change your user info to handle this error MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not foundTo fix this, adapt the following query by defining your username and password.
ALTER USER '<username>'@'<localhost>' IDENTIFIED WITH mysql_native_password BY '<your_password>'username: root
localhost: localhost
your_password: ************With this, you will be able to use your Sequel Pro; another great GUI (graphical) software we can use to interact with a MySQL database is TablePlus.
To connect from Sequel Pro or Sequel Ace:
- Host: 127.0.0.1
- User: the one you created
- Port: 3306
Common Error: caching_sha2_password
It is very common to encounter this error:
Authentication plugin 'caching_sha2_password' cannot be loadedThe solution that has worked best for me is changing the authentication method:
ALTER USER 'username'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'your_password';After this, Sequel Pro connects again without problems.
It comes with a free trial version that is perfect for our use, because it is not based on time, but limits the number of simultaneous connections you can make to the database. There are versions for macOS, Windows, and Linux.
TablePlus
Another excellent alternative is TablePlus. I personally use it a lot because:
- It's fast
- Modern interface
- Works very well with MySQL 8
- Has a free version sufficient for development
- It is available for macOS, Windows, and Linux.
FAQs about MySQL on macOS with Homebrew
- Does Homebrew work on Mac M1 and M2?
- Yes, it works perfectly on Apple Silicon.
- Is it mandatory to use mysql_secure_installation?
- No, but it is highly recommended.
- Can I use MySQL without a GUI?
- Yes, everything can be managed from the Terminal.
- Which GUI do you recommend?
- TablePlus or Sequel Ace, both work very well on macOS.
Conclusion
Installing MySQL on macOS with Homebrew is, today, the simplest and most stable way to work with MySQL on Mac. In a few commands, you can have a functional, secure environment ready for production or local development.
If you also correctly configure users, permissions, and graphical tools, you save yourself most of the errors that usually appear after installation.