How to install MySQL on MAC [OSX Catalina] (2020 Update)

Here’s a quick guide on how to install MySQL database on your Apple Macs.

This tutorial is aimed at Catalinas, but is high probable to work on other versions.

Installation

  1. Open up your terminal
  2. Install homebrew using a tutorial from the official homebrew’s site: https://brew.sh/
  3. restart your terminal (just in case)
  4. now open up the terminal again and run the command brew install mysql
  5. After a successful installation your MySQL server is ready

Access the console

  • my default, mysql server is installed on mac without a root password and you should be able to access the mysql’s console via command mysql -uroot
Homebrew’s instructions for usage of mysql server

Create and access a database

Creating a MySQL database is three-step process. Firstly, you need to create a user that will be used when connecting into the database from scrips, then you have to create the database and lastly, it is needed to grant the user the permissions to access the database.

1. Create a user

Access mysql console and run the following command:

CREATE USER 'myuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'myp4$$word';

You can replace “myuser” and the password “myp4$$word” with custom values.

2. Create a database

Within the mysql console run the following command:

CREATE DATABASE my_database_name;

You can replace “my_database_name” with the name of database you are creating.

3. Grant permissions

Now grant the user the permission to the database you have just created:

GRANT ALL PRIVILEGES ON my_database_name . * TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

Now your database should be ready to READ ‘n WRITE!

Troubleshooting

While installing mysql server on your mac you may encounter various issues. In general you might encounter the following:

  • while installing homebrew
  • while installing mysql via homebrew
  • while accessing mysql console
  • while creating a mysql database
  • while creating a mysql user

If you happen to encounter any issues, feel free to let me know in the comments below, try to follow the troubleshooting guide or simply google the error 🙂 .

Yours in coding,

Ivan

Sources:

Similar articles:

Leave a comment

Your email address will not be published. Required fields are marked *