Getting command line access to PHP and MySQL running MAMP on OSX

建立自己profile路径应该在/Users/yourname/,最后要运行. ./.profile使文件生效,和windows中给添加环境变量是一个道理,还可以看出linux和UNIX默认运行路径为

export PATH=/opt/local/bin:/opt/local/sbin:$PATH。
另外默认未修改用户可用
mysql  -uroot -proot -P3306进行登录

If you have MAMP installed on your Mac OS X box, you're probably going to want command line access to those applications at some point. Assuming you're running a default install you'll run into difficulty when you type php or mysql without logging into the appropriate directory. In MAMP the directories are as follows:

/Applications/MAMP/bin/php5/bin/php
/Applications/MAMP/Library/bin/mysql

Rather than referencing those full paths every time you'll probably want to include them in the PATH. You can do this by editing your .profile file. (You can get to the directory where this lives by typing cd).

Use a text editor to open up .profile and change the following line:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

To include the additions to the $PATH like so:

export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:$PATH

You'll probably need to make the shell reload your profile like so:

. ./.profile
../表示源文件所在目录的上一级目录
"."--代表目前所在的目录

Also if you have any problems connecting to mysql you may need to run the following command:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Thanks to the following blog entries:
http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variab…

更新

以上方法是通过更改个人命令行配置文件.profile来达到寻找到指定可运行程序目录的目的,之前更改可行,但是在重新启动系统后须重新运行

. ./.profile使个人配置文件生效,但不知道什么原因再次使用就不再管用了,后来通过直接更改bash的配置文件.bash_profile,
1)vim ~/.bash_profile;
2)添加
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:$PATH
3)保存退出; 
4)source ~/.bash_profile;
注意,直接修改bash配置文件一定要把路径配置完整,每一个路径是用:分隔开的,如果路径配置不完整将导致整个bash解释器基本命令都用不了了!
好吧,继续总结整个基础命令都用不了的解决办法
在新的commond line窗口中输入以下命令:
export PATH=/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
然后在sudo模式下回去重新修改原配置文件为完整状况。我这里的是:

export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php7.1.8/bin/:/opt/local/bin:/opt/local/sbin:$PATH

 








posted @ 2017-11-22 10:51  loanhicks  阅读(154)  评论(0编辑  收藏  举报