How to Install MySQL 9.7 on macOS with Homebrew
Install MySQL 9.7 LTS with Homebrew on Apple Silicon, run it as a local service, secure the root account, and create a restricted application user.
On this page
This guide installs MySQL 9.7 LTS with Homebrew on Apple Silicon. Use the explicit [email protected] formula: Homebrew’s unversioned mysql formula tracks the Innovation series, while [email protected] is deprecated. Check the current Homebrew formula and MySQL’s supported-platform matrix for current platform and bottle coverage.
If you already have data in MySQL 8.0, do not treat this as a fresh install or simply start the 9.7 service against the old data directory. Follow the MySQL 8.0 to 8.4 upgrade guide and the supported MySQL upgrade paths; upgrading from a release earlier than 8.4 to a release newer than 9.0 requires an 8.4 step.
Install MySQL 9.7 LTS
Update Homebrew and install the versioned LTS formula:
brew update
brew install [email protected]
The versioned formula is keg-only because it is an alternate MySQL version. Use its opt path in commands instead of linking it over another installed MySQL formula.
Start the local MySQL service
Start MySQL now and have Homebrew start it at login:
brew services start [email protected]
brew services info [email protected]
If the service does not start, check whether a configuration file from another MySQL installation is affecting it. Homebrew notes that /etc/my.cnf and /etc/mysql/my.cnf can interfere with its server. To see which option files this server checks, run:
"$(brew --prefix [email protected])/bin/mysqld" --verbose --help
Review the option-file paths near the start of the output and inspect any existing file before changing it; it may also be used by another MySQL installation. See MySQL’s option-file documentation.
Homebrew installs the server without a root password and configures it to accept connections from the local machine by default. Secure the root account before using it:
"$(brew --prefix [email protected])/bin/mysql_secure_installation"
Follow the prompts to set a strong root password. Do not expose the database port to other machines unless remote clients are required and network access has been deliberately configured. See the Homebrew formula instructions and MySQL’s initial account security guide.
Verify the installation
Connect with the root password prompt and check the server version:
"$(brew --prefix [email protected])/bin/mysql" --user=root --password --execute='SELECT VERSION();'
The client prompts for the password; avoid adding it to the command line.
Create a database and a restricted application account
Open an administrative MySQL session:
"$(brew --prefix [email protected])/bin/mysql" --user=root --password
At the MySQL prompt, create a database, a sample table, and an application account with only row-level privileges:
CREATE DATABASE appdb;
CREATE TABLE appdb.users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);
CREATE USER 'appuser'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'appuser'@'localhost';
MySQL returns the generated application password once. Save it securely. This account can read and change rows in appdb but cannot create or alter schema objects; use a separate migration account when schema changes are needed.
Test the application account from Terminal:
"$(brew --prefix [email protected])/bin/mysql" --user=appuser --password --database=appdb --execute='SELECT DATABASE();'
To manage the service later, use brew services stop [email protected] or brew services restart [email protected]. For more setup and administration guides, see the MySQL tutorial.