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.
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
- Run the Homebrew install script for MySQL:
brew install mysql
- Start the MySQL background service:
brew services start mysql
- Verify that MySQL is installed and that the service is running:
mysql --version
brew services list
- 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.
MySQL configuration can be adjusted in a file called my.cnf.
- 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
.
-
Open the file and edit or add to it as needed (see below for an example).
-
Save your changes.
-
Restart MySQL:
brew services restart mysql
- 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
- Open my.cnf and add a new line to the bottom to set the
sql_mode
variable. Copy and paste your currentsql_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
- 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
- Save and close my.cnf, and restart MySQL.