Install MySQL Locally on a Mac

MySQL is an open source relational database management system that is used as a component to help store data for web applications. You can install MySQL locally on a Mac following a few simple steps.

Firstly, head to the MySQL website and then to the Downloads section. Head to the Community Edition downloads and choose the MySQL Community Server option.

At the time of writing, MySQL version 5.7.18 can be downloaded.

Install MySQL Locally

Download the required package for your operating system and following the install wizard steps. At this point, you may be given a temporary password to allow you to use the mysql client.

After your computer confirms that MySQL has been installed successfully, you will need to locate the install location.

You should find the file contents within the following directory.

/usr/local/mysql

Now you should be able to use the command to start and stop mysqld as well as use the mysql client.

You can start mysqld by running the following command.

$ sudo /usr/local/mysql/support-files/mysql.server start
Password:
Starting MySQL
 SUCCESS! 

Similarly, use stop to stop the service.

$ sudo /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL
.. SUCCESS! 

To avoid having to use the absolute path each time when starting/stopping the service, you can set up aliases on your computer.

Add the following into the .bashrc, .bash_login or .bash_profile file.

alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop' 

This will allow you to simply run the mysqlstart and mysqlstopcommands to start and stop the service.

To use the mysql client, first ensure that the mysqld process is running (by using the commands above), then running the following.

$ /usr/local/mysql/bin/mysql -uroot -p

When prompted for a password, use the temporary password given to you during the MySQL installation process and you will be able to connect.

$ sudo /usr/local/mysql/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>