How to Create an Alias in Terminal for MAMP in MySQL on OS X?

2014-11-03 OS X

After MAMP is installed on OS X, you can use command line (terminal) to access MySQL in exactly the same way as on Linux. It’s very handy when you have to deal with importing or exporting huge SQL files. On of the things that can become little bit frustrating is that when normally you would like to access MySQL, you would type

mysql -u root -p

In OS X you have to provide full path to MySQL. Since the path is long (see below), it’s not a convenient way. To achieve the same as above you have to type

/Applications/MAMP/Library/bin/mysql -u root -p

In this article I will show you, how can we create an alias and access MySQL much faster.

Open terminal and go to you home directory

cd ~

Now create a new file called



touch ~/.bash_profile

Open this file

open .bash_profile

When an edit window will appear, type the following line (I assume that you didn’t change the default path where MAMP is installed. If you did, change it to a proper location).

alias mysql='/Applications/MAMP/Library/bin/mysql -u root -p'

Save the file by pressing

⌘ S

Quit the window by pressing

⌘ Q

We’re not done yet. Last step – force the change you’ve done to take effect. Since .bash_profile is executed every time you log in, we have to reload the content without rebooting.


source .bash_profile

Now you should be able to use mysql alias. Try it! After typing


you should be asked for root’s password. If you didn’t change it, it’s root, otherwise it’s the one you set after installing MAMP.

MAMP MySQL alias in OS X - part 2