简体   繁体   English

从终端访问 MAMP 的 MySQL

[英]Access MAMP's MySQL from Terminal

I want to practice using SQL instead of phpMyAdmin.我想练习使用 SQL 而不是 phpMyAdmin。

How do I log into MAMP's MySQL from the terminal?如何从终端登录 MAMP 的 MySQL?

I'm assuming the version of MAMP you're using installs itself in /Applications/MAMP.我假设您使用的 MAMP 版本安装在 /Applications/MAMP 中。 First make sure via the MAMP console that the Mysql server is on.首先通过 MAMP 控制台确保 Mysql 服务器已打开。 Then connect like this from command line:然后从命令行像这样连接:

/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!

If you just want to type:如果您只想输入:

mysql -u Username -p

Update for macOS Big Sur replace all ~/.bash_profile or ~/.profile with ~/.zshrc from the next commands. macOS Big Sur 的更新将所有~/.bash_profile~/.profile替换来自下一个命令的~/.zshrc

Check first if you have a file named ~/.bash_profile or ~/.profile or ~/.zshrc with the following command首先使用以下命令检查您是否有名为~/.bash_profile~/.profile~/.zshrc的文件

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 + X and then type Y and enter保存文件并使用CTRL + X退出 nano,然后输入Yenter

Then you need to type然后你需要输入

source ~/.bash_profile

Now you can use现在你可以使用

mysql -u root -p

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

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 终端中运行可执行文件

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

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

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.html and it worked perfectly.我无法使上述任何一项工作:/我去了http://blog-en.mamp.info/2009/08/using-mysql-command-line-with-mamp.html并且它工作得很好。 Hope this helps.希望这可以帮助。

Open a new terminal window , copy and paste the section below and TADA !打开一个新的终端窗口复制并粘贴下面的部分和TADA

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

这条线对我有用:

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

then然后

  ./mysql -u root -p

Enter Your Password...输入您的密码...

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

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