找不到 MySQL 命令 [MAMP]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17664021/
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 18:10:04  来源:igfitidea点击:

MySQL Command not Found [MAMP]

mysqlbashshellunixterminal

提问by IdeoREX

I'm working to set up my MySQL server using MAMP.

我正在努力使用 MAMP 设置我的 MySQL 服务器。

Current Status: Downloaded MySQL, MAMP Running MAMP: MySQL Server is green, plus it appears as a process in activity monitor

当前状态:已下载 MySQL,MAMP 正在运行 MAMP:MySQL 服务器是绿色的,而且它在活动监视器中显示为一个进程

I tried:

我试过:

$ mysql
-bash: mysql: command not found

I saw some tutorials that recommended adding a path to my .profile file. So I created a .profile file and added

我看到一些教程建议为我的 .profile 文件添加路径。所以我创建了一个 .profile 文件并添加了

PATH=$PATH:/Applications/MAMP/Library/bin
export PATH

I then saved it as .profile in the home directory.

然后我将它保存为主目录中的 .profile 。

Again I tried

我再次尝试

$ mysql
-bash mysql: command not found

Does anyone have any idea what's wrong?

有谁知道出了什么问题?

Thanks

谢谢

OS: Mountain Lion

操作系统:山狮

回答by Vincent Orback

A simple way is to just run

一个简单的方法就是运行

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

What this does is add a symbolic link for the mysql binary from MAMP into your executable path – in this case, within /usr/local/bin/

这样做是将 mysql 二进制文件的符号链接从 MAMP 添加到您的可执行路径 - 在这种情况下,在 /usr/local/bin/


Warning: If you've installed MySQL manually as well, this may interfere with that installation, so don't do this if you have!


警告:如果你也手动安装了 MySQL,这可能会干扰安装,所以如果你有,请不要这样做!

回答by justinkoh

This is MAMP for mac.

这是 Mac 版的 MAMP。

Firstly check the path where mysql command is located in your machine. For example mine is:

首先检查你的机器中mysql命令所在的路径。例如我的是:

/Applications/MAMP/Library/bin/mysql

Test entering that in terminal will get you some kind of mysql response depending if your login is successful. For e.g:

测试在终端中输入它会得到某种 mysql 响应,具体取决于您的登录是否成功。例如:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Now we'll want to add this in $PATH so that you only need to run "mysql" without the folders path.

现在我们要在 $PATH 中添加它,这样你只需要运行“mysql”而不需要文件夹路径。

To do that, first check $PATH, enter in terminal:

为此,首先检查 $PATH,在终端中输入:

echo $PATH

Next enter:

接下来输入:

nano .bash_profile

Add this one line (use your own mysql bin path):

添加这一行(使用您自己的 mysql bin 路径):

export PATH="/Applications/MAMP/Library/bin:$PATH"

Press Ctrl + o to save, press enter/return key to confirm the filename is .bash_profile.

按 Ctrl + o 保存,按回车/返回键确认文件名为 .bash_profile。

Then Press Ctrl + x to exit the editor.

然后按 Ctrl + x 退出编辑器。

Close the terminal. Re-open terminal. Enter:

关闭终端。重新打开终端。进入:

echo $PATH

Your $PATH now includes mysql bin path. You should now be able to call mysql command from any directory.

您的 $PATH 现在包括 mysql bin 路径。您现在应该能够从任何目录调用 mysql 命令。

Credits to http://coolestguidesontheplanet.com/add-shell-path-osx/

归功于http://coolestguidesontheplanet.com/add-shell-path-osx/

回答by Erik Ekman

MAMP docs (http://documentation.mamp.info/en/mamp/how-tos/using-mysql-command-line) says it should be here:

MAMP 文档(http://documentation.mamp.info/en/mamp/how-tos/using-mysql-command-line)说它应该在这里:

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot

回答by deagh

First you must verify the path to the mysql binary. After that you can extend (in ~/.profile) your PATH i.e.

首先,您必须验证 mysql 二进制文件的路径。之后你可以扩展(在 ~/.profile 中)你的 PATH 即

export PATH=$PATH:/path/to/mysql/bin/

After editing .profile you have to logout/login to active changes or source your .profile

编辑 .profile 后,您必须注销/登录以进行活动更改或获取您的 .profile

source ~/.profile