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

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:


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:…

I am unable to find .profile under Snow Leopard. Upon opening Terminal, I have tried the command "open .profile" Telnet replies, "The file /Users/Matthew/.profile does not exist." Any suggestions?

To anyone who is having problems getting Zend_Tool working on their MAC OS X (10.6) in Terminal, this is how to solve the problem.

Step 1
Download the Zend Framework to your downloads folder. Once downloaded, rename the folder ZendFramework

Step 2
Open Terminal and type: sudo cp -r ~/Downloads/ZendFramework /usr/local/ZendFrameworkCli

Step 3
In Terminal, type: open ~/.bash_profile

Note: If file is not found...
Open the application TextEdit. Create a new file and make sure you are typing in plain text only. Type the following: alias zf=/usr/local/ZendFrameworkCli/bin/

Save and exit TextEdit

Step 4
In Terminal, type: zf show version


Thought I would update the instructions here for MAMP 1.9

The path has changed to

First, make MAMP's php executable
chmod +x /Applications/MAMP/bin/php5.2/bin/php

then edit your path for the version of PHP you want to use:
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5.2/bin/:/opt/local/bin:/opt/local/sbin:$PATH

This was exactly what I was searching for, that symlink saved my - thank you!

I changed the password when I was in phpMyAdmin, the root by accident, then I got the following message:
/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect

How do I fix the root password in the terminal so that I can access the phpMyAdmin again.

hi I am trying to access mysql through the terminal and I keep getting this :Last login: Sat Jul 7 16:17:44 on ttys000
Diane-Friersons-MacBook-Pro:~ dianefrierson$ mysql -u root --password=admin-bash: mysql: command not found
Diane-Friersons-MacBook-Pro:~ dianefrierson$
I know that I'm connected because I use XAMPP and I can access mysql through the admin but I too am following a tutorial and would like to know both ways. please help thanks in advance.. Peace and Blessings

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.

About the Author

Joaquin Lippincott, CEO

Joaquin is a modern technology veteran. Throughout his career he has built successful digital strategies with a wide assortment of transformative technologies and platforms, helping clients identify a clear path for success. Over the years he has worked with industry leaders such as DC Comics, the Emmys, Intel, Technicolor, Verizon Wireless, Habitat for Humanity, Limewire, the Linux Foundation, Sony Pictures Television, Mercy Corps, and Cisco as well as numerous small businesses, advertising agencies and internet start ups. With over 14 years of experience in his field he is still as passionate about technology as ever. Joaquin is a graduate from UCLA with a degree in design and has also served on the AIGA Portland chapter board as President. Twitter: @joaquinlippinco