23

I'm working to set up my MySQL server using MAMP.

Current Status: Downloaded MySQL, MAMP Running MAMP: MySQL Server is green, plus it appears as a process in activity monitor

I tried:

$ mysql
-bash: mysql: command not found

I saw some tutorials that recommended adding a path to my .profile file. So I created a .profile file and added

PATH=$PATH:/Applications/MAMP/Library/bin
export PATH

I then saved it as .profile in the home directory.

Again I tried

$ mysql
-bash mysql: command not found

Does anyone have any idea what's wrong?

Thanks

OS: Mountain Lion

Gary Reckard
  • 277
  • 2
  • 13
IdeoREX
  • 1,455
  • 5
  • 22
  • 39
  • Do you _know_ where the `mysql` bin is? – Wrikken Jul 15 '13 at 21:17
  • have you restarted bash ? as it only reads on start up – exussum Jul 15 '13 at 21:18
  • Is there a `mysql` binary in /Applications/MAMP/Library/bin? Did you source the .profile or restart the shell? Run `echo $PATH` – Erik Ekman Jul 15 '13 at 21:18
  • echo $PATH ------> /usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/bin:/sbin:/usr/bin:/usr/sbin:/Users/msmith/bin:/opt/local/bin:/usr/local/mysql/bin:/usr/local/mysql/bin – IdeoREX Jul 15 '13 at 21:21
  • The MAMP dir was not in your path, and there seems to be no binary `mysql` inside it also.. Locate or install mysql client and try running it with an absolute path: `/bla/bla/foo/bin/mysql` – Erik Ekman Jul 15 '13 at 21:28
  • I read the wrong file directory. /Application/MAMP/Library/bin/ contains mysql, mysql_[client_test, config, convert_table_format, find_rows, fix_extensions, plugin, secure_installation......] – IdeoREX Jul 15 '13 at 21:56
  • I have the exact same problem. And none of the answers got it fixed. Can you please tell me how you fixed it? – Chintan Parekh Jun 01 '14 at 07:20
  • duplicate of http://stackoverflow.com/questions/10577374/mysql-command-not-found?rq=1 – justinkoh Dec 18 '14 at 07:23

4 Answers4

62

A simple way is to just run

sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql

What this does is add a symbolic link for the mysql binary from MAMP into your executable path – in this case, within /usr/local/bin/


Warning: If you’ve installed MySQL manually as well, this may interfere with that installation, so don’t do this if you have!

Vincent Orback
  • 2,327
  • 22
  • 35
  • Worked great in 2022 for MAMP Pro! Had a PHP script that relied on mysql being available, and now it works perfectly with the MAMP MySQL. – jerclarke Jul 18 '22 at 18:56
21

This is MAMP for mac.

Firstly check the path where mysql command is located in your machine. For example mine is:

/Applications/MAMP/Library/bin/mysql

Test entering that in terminal will get you some kind of mysql response depending if your login is successful. For e.g:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Now we'll want to add this in $PATH so that you only need to run "mysql" without the folders path.

To do that, first check $PATH, enter in terminal:

echo $PATH

Next enter:

nano .bash_profile

Add this one line (use your own mysql bin path):

export PATH="/Applications/MAMP/Library/bin:$PATH"

Press Ctrl + o to save, press enter/return key to confirm the filename is .bash_profile.

Then Press Ctrl + x to exit the editor.

Close the terminal. Re-open terminal. Enter:

echo $PATH

Your $PATH now includes mysql bin path. You should now be able to call mysql command from any directory.

Credits to http://coolestguidesontheplanet.com/add-shell-path-osx/

justinkoh
  • 995
  • 10
  • 14
6

MAMP docs (http://documentation.mamp.info/en/mamp/how-tos/using-mysql-command-line) says it should be here:

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
Erik Ekman
  • 2,051
  • 12
  • 13
2

First you must verify the path to the mysql binary. After that you can extend (in ~/.profile) your PATH i.e.

export PATH=$PATH:/path/to/mysql/bin/

After editing .profile you have to logout/login to active changes or source your .profile

source ~/.profile
deagh
  • 2,647
  • 1
  • 30
  • 29