27

I installed MySQL on my Mac, and now I would like to add it to my $PATH variable. I want to be able to type mysql anywhere.

I tried adding the following to my .profile file:

export PATH=${PATH}/usr/local/mysql/bin/

I have restarted my Terminal but it does not do the trick. It still says: -bash: mysql: command not found.

How can I add this properly to my $PATH?

I am using OS X Yosemite.

37

Here is why your current code is not working:

export PATH=${PATH}/usr/local/mysql/bin/

You forgot the colon.

export PATH=${PATH}:/usr/local/mysql/bin/

is the correct code.

  • People upvoting, where did you get this faulty path from? – Spotlight Jul 28 '16 at 1:44
  • 1
    For this to work for me, I also had to reload the .bash_profile from the command line, by running: source ~/.bash_profile – Isak La Fleur Sep 23 '17 at 15:01
18

Try adding the following line to your .bash_profile file.

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

You can do this easily with the following command, which will append the line if the file already exists or create a new file with the line if it doesn't.

echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.bash_profile
  • With MAMP: export PATH="/Applications/MAMP/Library/bin:$PATH" – Matt R Jun 12 at 22:46
6

You can accomplish this by going to your .bash_profile file and adding these lines to it.

alias mysql.start="sudo /usr/local/mysql/support-files/mysql.server start"
alias mysql.stop="sudo /usr/local/mysql/support-files/mysql.server stop"
alias mysql.restart="sudo /usr/local/mysql/support-files/mysql.server restart"
alias mysql.status="sudo /usr/local/mysql/support-files/mysql.server status"

After you've done this you can start, stop, restart and check the status of your connection anywhere in your terminal like this:

mysql.start - starts mysql
mysql.stop - stop mysql
mysql.restart - restarts mysql
mysql.status - checks the status of mysql

Hope that helps even tho I might be late. CHEERS!

0

You can also use an alias to do things like setting username and database.

In .bash_profile ( just .profile on some systems )

alias mysql='/usr/local/mysql/bin/mysql -u username --default-character-set=utf8' -p databasename

logout and open a new terminal or it won't get setup

Now typing mysql will ask for your database password and take you straight there, instead of fiddling with the options each time.

0

If you need to modify your .bash_profile file, take a look at this article: My Mac Osx Bash Profile, which is very helpful and easy to understand.

It solved my $PATH issue (which appeared out of nowhere).

-3

edit the system wide configuration file:

/etc/paths
  • This file gets overwritten by every OS X upgrade. – nohillside Oct 29 '15 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .