在 OS X 10.7 中找不到 Mysql 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10577374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:22:09  来源:igfitidea点击:

Mysql command not found in OS X 10.7

mysql

提问by SilverNightaFall

I cant get my mysql to start on os x 10.7. It is located in /usr/local/mysql/bin/mysql

我无法让我的 mysql 在 os x 10.7 上启动。它位于/usr/local/mysql/bin/mysql

I get command not found when I type mysql --versionin the terminal.

当我mysql --version在终端中输入时,我找不到命令。

I tried this can't access mysql from command line macbut still get command not found. I tried installing mysql with the dmg and i have tried to install it through homebrew and I cant get it to work. When I try to start mysql with homebrew I get MySQL won't start

我试过这无法从命令行mac访问mysql但仍然找不到命令。我尝试用 dmg 安装 mysql,我尝试通过自制软件安装它,但我无法让它工作。当我尝试使用自制软件启动 mysql 时,我发现MySQL 无法启动

This is my $PATH:

这是我的$PATH

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/Users/Victoria/bin:/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/Users/Victoria/bin:/usr/local //usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin

回答by Hophat Abc

This is the problem with your $PATH:

这是您的 $PATH 的问题:

/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin.

/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin.

$PATHis where the shell searches for command files. Folders to search in need to be separated with a colon. And so you want /usr/local/mysql/bin/in your path but instead it searches in /usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin, which probably doesn't exist.

$PATH是 shell 搜索命令文件的地方。要搜索的文件夹需要用冒号分隔。所以你想要/usr/local/mysql/bin/在你的路径中,而是在 中搜索/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin,这可能不存在。

Instead you want ${PATH}:/usr/local/mysql/bin.

相反,你想要${PATH}:/usr/local/mysql/bin.

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

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

If you want this to be run every time you open terminal put it in the file .bash_profile, which is run when Terminal opens.

如果您希望每次打开终端.bash_profile时都运行它,请将其放入文件中,该文件在终端打开时运行。

回答by SreerajS

I faced the same issue, and finally i got a solution. Please go through with the below steps, if you are using MAMP.

我遇到了同样的问题,最后我得到了解决方案。如果您使用 MAMP,请完成以下步骤。

  1. Start MAMP or MAMP PRO
  2. Start the server
  3. Open Terminal (Applications -> Utilities)
  4. Type in: (one line) ? /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
  1. 启动 MAMP 或 MAMP PRO
  2. 启动服务器
  3. 打开终端(应用程序 -> 实用程序)
  4. 输入:(一行)?/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot

This works for me.

这对我有用。

回答by gzc

One alternative way is creating soft link in /usr/local/bin

一种替代方法是在 /usr/local/bin

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

But if you need other executables like mysqldump, you will need to create soft link for them.

但是,如果您需要其他可执行文件,例如mysqldump,则需要为它们创建软链接。

回答by shivam

You have to set PATH for mysql in your .bashrcfile using following:

您必须.bashrc使用以下方法在文件中为 mysql 设置 PATH :

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

But If you are using oh my zshthen you have to add path inside .zshrcfile.

但是如果你正在使用,oh my zsh那么你必须在.zshrc文件中添加路径。

回答by nurealam siddiq

Your PATHmight not setup. Go to terminal and type:

您的PATH可能未设置。转到终端并输入:

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

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

Essentially, this allows you to access mysql from anywhere.

本质上,这允许您从任何地方访问 mysql。

Type cat .bash_profileto check the PATH has been setup.

键入cat .bash_profile以检查 PATH 是否已设置。

Check mysqlversion now: mysql --version

现在检查mysql版本:mysql --version

If this still doesn't work, close the terminal and reopen. Check the version now, it should work. Good luck!

如果这仍然不起作用,请关闭终端并重新打开。现在检查版本,它应该可以工作。祝你好运!

回答by Hymanie Santana

If you installed MySQL Server and you still get

如果你安装了 MySQL Server 并且你仍然得到

mysql -u root -p command not found

You're most likely experiencing this because you have an older mac version.

您很可能会遇到这种情况,因为您使用的是较旧的 mac 版本。

Try this:

尝试这个:

in the home directory in terminal open -t .bash_profile

在终端的主目录中 open -t .bash_profile

paste export PATH=${PATH}:/usr/local/mysql/bin/inside and save it

粘贴export PATH=${PATH}:/usr/local/mysql/bin/进去并保存

instead of writing mysql -uroot -ppaste the following in your terminal:

而不是mysql -uroot -p在终端中粘贴以下内容:

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

Enter your password. Now you're in.

输入您的密码。现在你进来了。

回答by Jon Gear

If you are using terminal you will want to add the following to ./bash_profile

如果您正在使用终端,您需要将以下内容添加到 ./bash_profile

export PATH="/usr/local/mysql/bin:$PATH"

export PATH="/usr/local/mysql/bin:$PATH"

If you are using zsh, you will want to add the above line to your ~/.zshrc

如果您使用的是 zsh,则需要将以上行添加到您的 ~/.zshrc

回答by zazu

I have tried a lot of the suggestions on SO but this is the one that actually worked for me:

我已经尝试了很多关于 SO 的建议,但这是对我真正有用的建议:

sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'

then you type

然后你输入

mysql

It will prompt you to enter your password.

它会提示您输入密码。

回答by KayV

Add the following lines in bash_profile:

在 bash_profile 中添加以下几行:

alias startmysql='sudo /usr/local/mysql/support-files/mysql.server start'
alias stopmysql='sudo /usr/local/mysql/support-files/mysql.server stop'

and save the bash_profile.

并保存 bash_profile。

Now, in the terminal start and stop the mysql server using the following commands:

现在,在终端中使用以下命令启动和停止 mysql 服务器:

startmysql //to start mysql server

and

stopmysql //to stop mysql server

回答by zod

I installed MAMP and phpmyadmin was working.

我安装了 MAMP 并且 phpmyadmin 正在工作。

But cannot find /usr/local/bin/mysql

但是找不到/usr/local/bin/mysql

This fixed it

这修复了它

sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql