You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

M1 Mac终端中mysql命令提示‘command not found’的zshrc配置方法咨询

Fixing "mysql: command not found" on M1 Mac

Hey there! Let's get that MySQL command working on your M1 Mac right away. Here's a step-by-step breakdown tailored to your situation:

1. Correct the PATH export line for your MySQL installation

Your specific MySQL bin path is /usr/local/mysql-8.0.27-macos11-arm64/bin, so the exact line you need to add to ~/.zshrc is:

export PATH=$PATH:/usr/local/mysql-8.0.27-macos11-arm64/bin

This line tells your shell to append MySQL's executable directory to the system's existing PATH variable. That way, when you type mysql, your terminal knows to look in this folder for the command.

2. Where to place this line in ~/.zshrc

Since your ~/.zshrc already has existing configurations, the safest place to add this line is at the very end of the file. Here's why:

  • Zsh reads configurations top-to-bottom, so adding it at the end ensures it doesn't get overwritten by any earlier PATH resets.
  • It keeps your MySQL-specific path separate from other system or app configurations, making it easier to find and update later if you upgrade MySQL.

3. How to add and activate the configuration

If you're using nano (a simple terminal text editor) to edit ~/.zshrc:

  • Scroll all the way to the bottom of the file using the arrow keys.
  • Paste the export PATH line you copied earlier.
  • Press Ctrl + O to save the changes, then press Enter to confirm the filename.
  • Press Ctrl + X to exit nano.

To make the changes take effect immediately (without restarting your terminal), run:

source ~/.zshrc

4. Verify it works

Test if the mysql command is now recognized by running:

mysql --version

If you see the MySQL version number printed, you're all set!

Quick note on "MySQL专用" path

The line we're adding is already dedicated to MySQL—it only adds the directory where MySQL's command-line tools (like mysql, mysqldump, etc.) live to your system's command search path. There's no need for extra steps to "specify it as MySQL-only"—this configuration does exactly that.

内容的提问来源于stack exchange,提问作者EntzY

火山引擎 最新活动