MySQL not working on mountain lion

I'm using mountain lion, I have installed MySQL.

GUI

mysql server

It shows MySQL is running, but when I type

mysql --version 

It gives error "mysql: command not found"


Solution 1:

export PATH="/usr/local/mysql/bin:$PATH"

in .bashrc or .bash_profile file (cd ~/.bash_profile)

This will tell your terminal where to find mysql command.

Solution 2:

command not found just means that the executable you're trying to run is not found in any of the directories in your $PATH environment variable.

Try /usr/local/mysql/bin/mysql

The documentation links include a platform guide where it tells you that MySQL gets installed into /usr/local/, and then a symlink is created at /usr/local/mysql that points to this install dir. Here you can see that I've installed two versions, and that symlink was updated on the last install:

$ ls -ld /usr/local/mysql*
lrwxr-xr-x   1 root  wheel   27 Apr  4  2012 /usr/local/mysql -> mysql-5.5.22-osx10.6-x86_64
drwxr-xr-x   3 root  wheel  102 Apr  4  2012 /usr/local/mysql-5.5.18-osx10.6-x86_64
drwxr-xr-x  16 root  wheel  544 Mar  2  2012 /usr/local/mysql-5.5.22-osx10.6-x86_64

I don't recall what change I made to put /usr/local/mysql/bin into my PATH, but in my opinion, the cleanest way to do that for all users is

sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'

and open a new tab in Terminal to get the effect immediately.