Install MySQL 8 on MacOS

In this tutorial, we show the detailed steps to install MySQL 8 on MacOS.

There are two ways to install MySQL server on MacOS: install using brew and install via installation package.

Install MySQL using brew

On MacOS, we can install MySQL easily using brew.

Install MySQL

brew install mysql

Start the MySQL server

brew services start mysql

Configure MySQL server

We need to run the following script to configure the security of the MySQL server:

mysql_secure_installation

During this process, you can set the root account password and configure some options to enhance the security of the MySQL server. You will see output similar to the following:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

Manage MySQL server commands

Brew provides useful commands to manage the MySQL server.

  • brew services start mysql: Start the MySQL server and set it to self-start at reboot.
  • brew services stop mysql: Stop the MySQL server and set it not to start automatically.
  • brew services run mysql: Start the MySQL server.
  • mysql.server start: Start the MySQL server.
  • mysql.server stop: Stop the MySQL server.

Install MySQL using native package

The process of installing MySQL using native package has a friendly UI interface, which is more convenient and faster.

Download Native Package Installer

Please click here to download the dmg file of MySQL community version. It contains the MySQL installer.

Install MySQL

After downloading the Native Package, please follow the steps below to install:

  1. Double-click the dmg file, you will see a MySQL installer file, such as: mysql-8.0.26-macos-10.13-x86_64.pkg. Double-click the MySQL installer file.

  2. On the “Introduction” page, directly click the “Continue” button.

  3. On the “License” page, directly click the “Continue” button.

  4. On the “Installation Type” page, you can directly click the “Install” button, or click the “Customize” button to select the components to be installed and then click the “Install” button.

  5. On the “Configuration” page, select Use Strong Password Entryption as password encryption policy. Then, enter the password of the root user. Click the “Finish” button to complete the installation.

Manage MySQL

The MySQL preference pane will be installed by default. You can find it in the System Preferences window. The MySQL preference pane allows you to start, stop, and configure MySQL.

MySQL preference pane

Conclusion

In this article, we showed the detailed steps of installing MySQL in macos, and introduced several commands for managing MySQL server.

If you use other operating system platforms, please use the following tutorial: