Install MySQL on a Mac

Below are the steps that I used to install MySQL on my M1 Mac via the Homebrew package manager.

As mentioned, this is an M1 Mac (which uses the ARM64 architecture) but that didn’t cause any issues. The current version (MySQL 8.0.26) supports the ARM architechure.

Install Homebrew

Seeing as I’m installing MySQL via Homebrew, it requires that Homebrew is installed.

You can skip this step if you’ve already got Homebrew installed.

To install these prerequisites, open a Terminal window and run the following commands.

Install Xcode:

xcode-select --install

Install Homebrew:

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

That’s it. Xcode and Homebrew should be installed once those commands have been run.

But before we move on, here’s how to check Homebrew:

brew doctor

Follow any prompts to fix any problems that may have been encountered.

While we’re at it, here’s how to update Homebrew:

brew update

If you’re already up to date, you’ll get a message to that effect.

Install MySQL

Now that Homebrew is installed, let’s go ahead and install MySQL:

brew install mysql

Wait patiently while it downloads and installs everything.

Once installed, the following message appears:

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To start mysql:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql

That message provides useful information for getting started.

Start MySQL

Now that we’ve installed MySQL, let’s start it using the first method listed above:

brew services start mysql

That should eventuate in a message like this:

Successfully started `mysql` (label: homebrew.mxcl.mysql)

Connect to MySQL

Once MySQL has started, we can go ahead and connect to it:

mysql -uroot

Once connected, you should see something like this:

MySQL [(none)]>

You can now go ahead and start using MySQL.

Here’s an example of a quick command you can use to see a list of databases:

show databases;

Result:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.007 sec)

Alternatives to Homebrew

If you don’t want to use Homebrew, you can install it via the Native Package Installer, which uses the native macOS installer (DMG) to walk you through the installation of MySQL.

Or, you could use the compressed TAR archive, which uses a file packaged using the Unix tar and gzip commands.

See the MySQL Installation Guide on the MySQL website for more information.