The mysql command is not found in the terminal on a Mac
zsh: command not found: mysqlShort 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.
Fix it fast
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 $PATH2Match what you see, then jump to its fix
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/mysql2Fix
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 ~/.zshrc3Verify
The client prints its version.
mysql --versionConfirmed by dev.mysql.com
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.42Fix
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.43Verify
A new terminal finds the client.
which mysql && mysql --versionConfirmed by docs.brew.sh
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver fails to resolve Maven dependencies when downloading a database driver
A driver library does not download automatically
DBeaver downloads driver jars from a Maven repository.
3 causes, each with a fixDatabases
DBeaver cannot verify the MySQL server certificate
unable to find valid certification path to requested target
DBeaver's MySQL driver is checking the server certificate and Java does not trust the CA that signed it.
2 causes, each with a fix