简体   繁体   English

如何在 Zsh 中修复“找不到命令:mysql”

[英]How to fix "command not found: mysql" in Zsh

I want to use MySQL with my Rails application.我想在我的 Rails 应用程序中使用 MySQL。

After successfully installing the package and seeing the option to start and stop the server from the Preference Pane, if I execute成功安装软件包并从首选项窗格中看到启动和停止服务器的选项后,如果我执行

mysql --version

I get an error from zsh:我从 zsh 收到一个错误:

zsh: command not found: mysql

I understand that this has something to do with my $PATH variable and if I display my $PATH I get:我知道这与我的$PATH变量有关,如果我显示我的$PATH我得到:

/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/aniruddhabarapatre1/.rvm/gems/ruby-2.2.1/bin:/Users/aniruddhabarapatre1/.rvm/gems/ruby-2.2.1@global/bin:/Users/aniruddhabarapatre1/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/Users/aniruddhabarapatre1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/opt/ImageMagick/bin:/usr/local/MacGPG2/bin:/Users/aniruddhabarapatre1/.rvm/bin

How do I resolve this error to get Mysql up and running?如何解决此错误以启动并运行 Mysql?

You paste this line to append the path to MySQL to your environment variables:您粘贴此行以将 MySQL 的路径附加到您的环境变量中:

export PATH=${PATH}:/usr/local/mysql/bin/

Then reload your environment variables with one of the following commands:然后使用以下命令之一重新加载您的环境变量:

source ~/.zshrc   # If you use Oh-My-Zsh
source ~/.bashrc  # If you use Default Bash

On the latest MacOS, Catalina, I used this open the zsh config and edit:在最新的 MacOS Catalina 上,我使用它打开 zsh 配置并编辑:

vi ~/.zshrc  

and added并添加

export PATH=${PATH}:/usr/local/mysql/bin/

then ran然后跑

source ~/.zshrc                            

to make it work让它发挥作用

Reopen a teminal and run mysql -u root -p , input the password and you can log into your MySQL account.重新打开一个终端并运行mysql -u root -p ,输入密码,您就可以登录到您的 MySQL 帐户。

On MacOs Catalina, open a terminal and run:在 MacOs Catalina 上,打开终端并运行:

 sudo nano /etc/paths

And add to end of file:并添加到文件末尾:

/usr/local/mysql/bin

Save the changes and quit, then reload the terminal.保存更改并退出,然后重新加载终端。

Open a new terminal and run:打开一个新终端并运行:

 mysql -u root -p

This was a problem within my configuration and $PATH variable.这是我的配置和$PATH变量中的问题。 I followed the " How to install MySQL on Mac OS X El Capitan " tutorial to resolve this.我按照“ 如何在 Mac OS X El Capitan 上安装 MySQL ”教程解决了这个问题。

In my terminal, I opened up the configuration by running vi ~/.zshrc , then located the line to export my PATH在我的终端中,我通过运行vi ~/.zshrc打开了配置,然后找到了导出我的 PATH 的行

export PATH="..."

and appended并附加

:/usr/local/mysql/bin

to it which resolved my issue.解决了我的问题。

For my MacOS Catalina system I tried everything above, but it didn't work.对于我的 MacOS Catalina 系统,我尝试了上述所有方法,但没有成功。 Input the code in your terminal:在终端中输入代码:

/usr/local/mysql/bin/mysql -uroot -p

Thanks go to the " How to Install MySQL on MacOS Big Sur " video.感谢观看“如何在 MacOS Big Sur 上安装 MySQL ”视频。

It worked also for MacOS Big Sur with an ARM processor.它也适用于带有 ARM 处理器的 MacOS Big Sur。

就我而言,这些步骤有所帮助:

  1. export PATH=$PATH:/usr/local/Cellar/mysql/8.0.25_1/bin
  2. mysql -u root -p

In the terminal run:在终端运行:

export PATH=/usr/local/Cellar/mysql/8.0.26/bin:$PATH

Then, if you run:然后,如果你运行:

mysql

It should return:它应该返回:

Access denied for user 'user'@'localhost' (using password: NO)

Run:跑:

mysql -u root -p

It should ask for your password and then be good to go.它应该询问您的密码,然后一切顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM