Skip to content

Instantly share code, notes, and snippets.

@samuelbradshaw
Last active August 4, 2022 02:03
Show Gist options
  • Save samuelbradshaw/2d435571fa0509f1bf732ecdd3e4f428 to your computer and use it in GitHub Desktop.
Save samuelbradshaw/2d435571fa0509f1bf732ecdd3e4f428 to your computer and use it in GitHub Desktop.
Installing MySQL on macOS

Installing MySQL on macOS

These instructions allow you to install MySQL on macOS. The instructions were tested on an Apple Silicon Mac, but the process on an Intel Mac should be similar.

Install Homebrew

Homebrew is a popular package manager that makes it easy to install command line tools. If you don’t yet have Homebrew installed, instructions can be found here: https://brew.sh

Verify that Homebrew is installed:

brew -v

Install MySQL

  1. Run the Homebrew install script for MySQL:
brew install mysql
  1. Start the MySQL background service:
brew services start mysql
  1. Verify that MySQL is installed and that the service is running:
mysql --version
brew services list
  1. Verify that you can connect to the database as the root user (the default password is blank):
mysql -u root -p

Sequel Ace is recommended as a GUI for connecting to MySQL databases.

Configure MySQL (optional)

MySQL configuration can be adjusted in a file called my.cnf.

  1. Find your my.cnf file:
mysql --help

You should see something like this:

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /opt/homebrew/etc/my.cnf ~/.my.cnf 

Note that there are multiple paths that MySQL will check for configuration variables. I chose to edit the file created by Homebrew at /opt/homebrew/etc/my.cnf.

  1. Open the file and edit or add to it as needed (see below for an example).

  2. Save your changes.

  3. Restart MySQL:

brew services restart mysql

Example configuration change: Adjust sql_mode

  1. Connect to MySQL and run this query to get your current sql_mode:
SELECT @@GLOBAL.sql_mode;

It should show something like this:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  1. Open my.cnf and add a new line to the bottom to set the sql_mode variable. Copy and paste your current sql_mode:
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  1. Make changes as needed. In my case, I wanted to disable ONLY_FULL_GROUP_BY, so I removed it:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  1. Save and close my.cnf, and restart MySQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment