Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Install MySQL on Apple Silicon Macs with Homebrew

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through installing MySQL on an Apple Silicon (M1/M2/M3) Mac using Homebrew. Homebrew is the most straightforward way to get MySQL running natively on ARM, avoiding the performance hit of running an x86 version through Rosetta 2. By the end, you'll have a working MySQL server, a secure root user, and the ability to start/stop the service easily.

What You'll Need

  • A Mac with Apple Silicon (M1, M1 Pro/Max, M2, M3, etc.) running macOS 12 or later (Monterey, Ventura, Sonoma, Sequoia).
  • Homebrew installed. If you don't have it, open Terminal and run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Command Line Tools for Xcode (Homebrew usually installs these automatically, but you can install them manually with xcode-select --install).
  • Basic familiarity with the Terminal app.

Step-by-Step

  1. Open Terminal. You can find it in Applications > Utilities, or search with Spotlight (Cmd+Space).
  2. Update Homebrew to ensure you have the latest package lists: brew update
  3. Install MySQL with the following command: brew install mysql. This downloads the ARM-native MySQL package and its dependencies. It may take a few minutes.
  4. Check the installation output. After the install completes, Homebrew will print a few notes. Pay attention to any caveats, especially the default root password (often blank) and how to start the service.
  5. Start MySQL as a background service (so it runs automatically at login): brew services start mysql. If you prefer to run it manually each time, use mysql.server start instead.
  6. Verify MySQL is running. Run mysql --version to see the client version, and mysqladmin ping to check if the server is responding. You should see mysqld is alive.
  7. Secure the installation. Run the security script to set a root password and remove insecure defaults: mysql_secure_installation. Follow the prompts: set a root password, remove anonymous users, disallow remote root login, remove the test database, and reload privileges.
  8. Test the connection. Log in as root with your new password: mysql -u root -p. Enter your password when prompted. You should see the mysql> prompt. Type exit to quit.

Common Mistakes

  • Forgetting to start the service. Installing MySQL doesn't start it. You must run brew services start mysql or mysql.server start before you can connect.
  • Using the wrong root password. On a fresh install, the root password is blank. If you try to log in with a password before running mysql_secure_installation, you'll get an access denied error. Use mysql -u root (no password) initially.
  • Assuming the default port is 3306. While 3306 is the default, if you have another MySQL instance (e.g., from Docker) or a previous install, the port might be occupied. Check with lsof -i :3306.
  • Not reading the Homebrew caveats. Homebrew often prints important setup instructions after installation. Scroll up in Terminal to see them.

Tips

  • Use a GUI tool. While the command line is powerful, tools like TablePlus, Sequel Ace, or MySQL Workbench make database management easier. They connect via the same socket or port.
  • Create a dedicated user. Instead of using root for your applications, create a user with limited privileges: CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'yourpassword'; then GRANT ALL PRIVILEGES ON mydb.* TO 'appuser'@'localhost';
  • Backup your databases regularly. Use mysqldump -u root -p mydb > backup.sql to create a backup, and restore with mysql -u root -p mydb < backup.sql.
  • Configure MySQL for your needs. The default configuration is fine for development. For production, you may want to adjust settings in /opt/homebrew/etc/my.cnf. Be careful: changing settings like innodb_buffer_pool_size can affect performance.

Troubleshooting

  • Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' – This means the server isn't running. Start it with brew services start mysql or mysql.server start.
  • Error: Access denied for user 'root'@'localhost' – The password is wrong or you're trying to use a password when none is set. Try mysql -u root without -p. If that fails, you may need to reset the root password (see below).
  • MySQL installs but won't start. Check the error log: cat /opt/homebrew/var/mysql/*.err. Common issues include port conflicts or permission problems. Ensure the data directory is owned by your user: sudo chown -R $(whoami) /opt/homebrew/var/mysql.
  • Forgot the root password. Stop MySQL (brew services stop mysql), then start it in safe mode: mysqld_safe --skip-grant-tables. In another terminal, run mysql -u root and execute: FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'; Then restart normally.
  • Homebrew says "mysql is already installed" but it's not working. This can happen if the binary is from an old install. Try brew reinstall mysql to get a clean copy.
  • Performance seems slow. If you're using an x86 version of MySQL (installed via Rosetta), consider reinstalling with brew reinstall mysql to get the ARM-native build. Check with file $(which mysql) – it should say "arm64".

Frequently Asked Questions

  1. Is MySQL on Apple Silicon slower than on Intel? No, the ARM-native version is actually faster for most workloads. The only slowdown occurs if you use an x86 version via Rosetta, which you should avoid.
  2. Can I run multiple MySQL versions with Homebrew? Yes, you can install specific versions like mysql@8.0 or mysql@5.7. They will be keg-only, so you'll need to add them to your PATH manually.
  3. How do I stop MySQL from starting automatically? Run brew services stop mysql. To disable it entirely, use brew services unload mysql.
  4. Where is the MySQL configuration file? The main config file is /opt/homebrew/etc/my.cnf. You can also place settings in ~/.my.cnf for user-specific overrides.
  5. How do I uninstall MySQL completely? Run brew uninstall mysql and then remove the data directory with rm -rf /opt/homebrew/var/mysql (backup your databases first!). Also remove any leftover files in /opt/homebrew/etc/my.cnf.
  6. Can I connect to MySQL from a GUI tool? Yes, any MySQL client can connect to localhost:3306 using the same credentials you set up via the command line.