Select Page

How to Install MySQL on Mac

by | MySQL, Programming, Tips

This tutorial will go through how to install MySql on MacOS using the Homebrew package manager.

Install Homebrew

You can skip this step if you already have Homebrew installed on your system. First open a terminal window and run the following commands:

Install Xcode:

xcode-select --install

Install Homebrew:

/bin/bash -c "$(curl -fsSL"

Once you have Hmoebrew, you can update it using the command:

brew update

If you are already up to date, Homebrew will inform you.

Install MySQL

To install MySQL using Homebrew, use the following command:

brew install mysql

This will take some time. Once the installation finishes you will get the following message:

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

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To restart mysql after an upgrade:
  brew services restart mysql
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql

It is advisable to go through the secure installation to get a password and remove anonymous users.

Start MySQL

Once you have installed MySQL you can start it using the command

brew services start mysql

If successful, you will get the following message:

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

Connect to MySQL

If you do not have a password set you can connect to MySQL using:

mysql -u root

If you have specified another username during the installation you would need to replace root with that name. If you have a password set, you can connect to MySQL using:

mysql -u root -p

This command will prompt you to enter your password. Once you have done so you will see the MySQL command line:


Now you are ready to start using MySQL! You can check what databases exist using the following command:

show databases;

This command will give you something similar to this output:

| Database           |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
4 rows in set (0.01 sec)

Alternatives to Homebrew

If you prefer an alternative method to Homebrew, you can install MySQL using the Native Package Installer, which uses the native macOS installer (DMG). Go to the official MySQL installation guide for more information on this installation process.

Have fun and happy researching!