How to use MAMP mysql from the command line

MAMP is a great program for easily developing web applications on your Mac computer.  It does have some idiosyncrasies that can have you pulling out your hair if you don’t know what to look for though.  One of them is using your the included ‘mysql’ from the command line.

In order to get this to work the first thing you have to do is included it in your PATH somehow.  I prefer to create symlink like this:

<br /> $sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql<br />

You will have to enter your Mac OS X root password (often the same as your own password).

Next you can run mysql from the command line:

<br /> $mysql<br />

But you might find that you get an error that looks something like this:

<br /> mysql> show tables in ;<br /> ERROR 1044 (42000): Access denied for user ''@'localhost' to database ''<br />

No problem you say, I can run as root, which is the user that MAMP says it is using anyway!

MAMP php Config

MAMP php Config (PRO)


MAMP Config (Free)

MAMP Config (Free)

So now you get something like this when you try to log in as root:

<br /> $mysql -uroot -p<br /> Enter password:<br /> ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)<br />

Now you are really confused. You start searching the inter-webs and find all sorts of crazy posts about how MAMP changed someone’s root password and what not. But you don’t need to worry! MAMP has not changed your root password. It is simply using it’s own user called root. It’s the root user for MAMP’s php, not for your computer.

In the free version of MAMP the root password is just ‘root’ again. In the PRO version you can change it to whatever you want under the php tab of the control panel! Hopefully this helps someone. I got stuck with this once and it took me way longer than it should have to figure out:)

comments powered by Disqus