Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

The mysql command is not found in the terminal on a Mac

Errorzsh: command not found: mysql

Short answer

The shell cannot find the mysql client because its folder is not in PATH. The macOS installer puts the binaries in /usr/local/mysql/bin. Homebrew's versioned MySQL formulae are keg-only and are not linked by default. Add the right bin folder to PATH, or link the formula, then open a new terminal.

  • Applies to macOS 15, MySQL 8.4 LTS, Homebrew
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out whether the binary exists and where.

    ls /usr/local/mysql/bin/mysql
    brew list --versions | grep -i mysql
    echo $PATH
  2. 2Match what you see, then jump to its fix

    1. 1/usr/local/mysql/bin/mysql exists but mysql alone is not found.Installed with the DMG package, folder not in PATHFix
    2. 2brew list shows a mysql formula such as mysql@8.4, but mysql is not on PATH.Installed with Homebrew as a keg-only versioned formulaFix

What does the error look like?

  • zsh: command not found: mysql

Cause 1 of 2

Installed with the DMG package, folder not in PATH

1Check

The package installs into a versioned folder under /usr/local with a symlink at /usr/local/mysql. Its bin folder is not added to PATH.

ls -l /usr/local/mysql

2Fix

Add the bin folder to PATH in your shell file. Current macOS uses zsh, so edit ~/.zshrc.

echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

3Verify

The client prints its version.

mysql --version

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 2

Installed with Homebrew as a keg-only versioned formula

1Check

A keg-only formula is installed in the Cellar and not linked into the default prefix, so most tools do not find it. brew info prints the PATH line to use.

brew info mysql@8.4

2Fix

Use the PATH instructions that brew info prints for the formula, or link it with brew link. Linking can shadow software that macOS ships, so prefer the PATH line.

brew info mysql@8.4
brew link mysql@8.4

3Verify

A new terminal finds the client.

which mysql && mysql --version

Confirmed by docs.brew.sh

Did this fix it?

How do I stop it coming back?

  • Use one install method only, either the package or Homebrew, so there is one bin folder to track.
  • Put PATH changes in ~/.zshrc, not typed into a single window.
  • After an upgrade, run brew info for the formula and check its PATH note.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.