Tech tips & other words

Add MySQL to terminal shell in Mac OS X

Mac OS X 10.6 snow leopard uses the bash shell by default. If you install MySQL from the disk image (dmg) from http://dev.mysql.com/downloads/, you can make it easy to access the mysql binary from the command line by adding it to your bash path.

Here’s how:

Open terminal, and type:

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

This adds the default location of the MySQL binary to your shell environment.

Then, you need to force the system to reload your .bash_profile file. Again, from terminal, enter:

. ~/.bash_profile

You can check your environment variables by typing in terminal:

env

Now, to access MySQL from the command line, you only need enter:

mysql

9 Comments

  1. Conor Turner

    You sir are the greatest man ever to have graced the earth with your presence. To simple commands solved a problem 2 hours of data reference guides couldn’t.

  2. Thomas guesnon

    Thanks !

  3. Nick Beranek

    That’s it?! Thank you!

  4. Christoph

    Thank you very much!

  5. Oliver Xu

    Thanks a lot! Nice and simple.

  6. mewb

    effusive praise and thanks: you have saved me a lot of head scratching and hair pulling.

  7. Syed

    I receive an error:

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

  8. Chris Brewer

    Perhaps your MySQL installation and PHP are looking in different places for the socket file. From command line (terminal), execute mysqladmin variables to view the location of the socket. See http://support.apple.com/kb/TS1999?viewlocale=en_US&locale=en_US for some possibly related issues.

  9. Nicholas

    Excellent stuff.. thank you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.