php 从终端访问 MAMP 的 MySQL

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

Access MAMP's MySQL from Terminal

phpmysqlbashterminalmamp

提问by Don P

I want to practice using SQL instead of phpMyAdmin.

我想练习使用 SQL 而不是 phpMyAdmin。

How do I log into MAMP's MySQL from the terminal?

如何从终端登录 MAMP 的 MySQL?

回答by Ray

I'm assuming the version of MAMP you're using installs itself in /Applications/MAMP. First make sure via the MAMP console that the Mysql server is on. Then connect like this from command line:

我假设您使用的 MAMP 版本安装在 /Applications/MAMP 中。首先通过 MAMP 控制台确保 Mysql 服务器已打开。然后从命令行像这样连接:

/Applications/MAMP/Library/bin/mysql -uUsername -pPassword

Obviously replace Username and Password. BTW, there is no space between -u and the Username or -p and the Password.

显然替换用户名和密码。顺便说一句, -u 和用户名或 -p 和密码之间没有空格。

Good Luck learning Mysql the old fashion way!

祝你好运以旧时尚的方式学习Mysql!

回答by caramba

If you just want to type:

如果您只想输入:

mysql -u Username -p

You can create an alias in your ~/.bash_profilein older OSX versions this file was called ~/.profileso best check first with

您可以~/.bash_profile在旧的 OSX 版本中创建一个别名,这个文件被称为~/.profile所以最好先检查

ls -la ~/

If one of those files exist, edit that file. Else, create a new one with what ever editor you like (here I do it with nano and have a ~/.bash_profile file)

如果存在这些文件之一,请编辑该文件。否则,用你喜欢的任何编辑器创建一个新的(这里我用 nano 来做,并有一个 ~/.bash_profile 文件)

sudo nano ~/.bash_profile

insert following line

插入以下行

alias mysql=/Applications/MAMP/Library/bin/mysql

Save the file and quit nano with CTRL + Xand then type Yand enter

保存文件并退出nano,CTRL + X然后输入Yenter

Then you need to type

然后你需要输入

source ~/.bash_profile

Now you can use

现在你可以使用

mysql -u root -p

回答by Mwirabua Tim

Just simply create a symbolic link to the MAMP mysql.

只需简单地创建一个指向 MAMP mysql 的符号链接。

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

Then you can easily call it from any directory like this:

然后你可以轻松地从任何目录调用它,如下所示:

mysql -uUsername -pPassword

回答by TlonXP

I had to do a little modification, first go to the bin folder

只好稍微修改一下,先进入bin文件夹

cd /Applications/MAMP/Library/bin/

then to run mysql file a had to execute

然后运行mysql文件必须执行

./mysql -uUSERNAME -pPASSWORD

The reason was that: Running an executable in Mac Terminal

原因是:在 Mac 终端中运行可执行文件

回答by user3474459

I could not get any of the above working :/ I went to http://blog-en.mamp.info/2009/08/using-mysql-command-line-with-mamp.htmland it worked perfectly. Hope this helps.

我无法使上述任何一项工作:/我去了http://blog-en.mamp.info/2009/08/using-mysql-command-line-with-mamp.html并且它工作得很好。希望这可以帮助。

Open a new terminal window, copy and pastethe section below and TADA!

打开一个新的终端窗口复制并粘贴下面的部分和TADA

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

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

回答by Chris Rosenau

If you want to do it on Windows type:

如果您想在 Windows 上执行此操作,请键入:

 c:/MAMP/bin/mysql/bin/mysql.exe -u username -p dbname < data.sql

回答by DarkSide

This line works for me:

这条线对我有用:

/Applications/MAMP/Library/bin/mysql -uroot -p