Shortcut to MySql on Mac OS X?

17,820

It depends on whether or not you want all user accounts to have access to MySQL, or just you.

For everyone, edit /etc/profile as instructed and add the following to the end:
export PATH=$PATH:usr/local/mysql/bin

For just you (ALSO, this is safest so you don't accidentally mess up any system variables!):

Get a terminal session: Launch Terminal if it's not already running.

Make sure you're in your home directory:
CD ~

See if .bash_profile exists:
ls -al .b*

If it does, open it with your favorite text editor. If it doesn't, launch your favorite text editor and Save as... .bash_profile in your home folder.

Add this line to .bash_profile and Save:
export PATH=$PATH:/usr/local/mysql/bin

Then close Terminal and open again for the change to take effect.


Hope this works out for you.

Share:
17,820
sscirrus
Author by

sscirrus

Updated on June 20, 2022

Comments

  • sscirrus
    sscirrus almost 2 years

    I am trying to add a path so I don't have to keep typing usr/local/mysql/bin every time I want to start Mysql. I found instructions here that say:

    Edit the file /etc/profile and update the path by adding: usr/local/mysql/bin/, for example: PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin"

    Problems:
    1. There is no existing line in my profile file that says 'path'. This is what it currently says in profile: # System-wide .profile for sh(1)

    if [ -x /usr/libexec/path_helper ]; then
        eval '/usr/libexec/path_helper -s'
    fi
    if [ "${BASH-no}" != "no" ]; then
        [ -r /etc/bashrc ] && . /etc/bashrc
    fi
    

    2. I really have no idea what I'm doing on a mac (yet). What do I add/change to the above file so mysql is easier to access?

  • sscirrus
    sscirrus over 13 years
    Hi Matt, I added the line to bash_profile but after restarting Terminal, it isn't working. I still have to type in the full /usr/local/mysql/bin/mysql -u root -p. .bash_profile now looks like this: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" export PATH=$PATH:usr/local/mysql/bin.
  • MattT
    MattT over 13 years
    Hm. Try this. In Terminal type "echo $PATH" to make sure "/usr/local/mysql/bin" is actually in the path. Also, at the end of the export line you added, does it actually say "export PATH=$PATH:usr/local/mysql/bin." exactly? Because as quoted in your response there's a period after the /bin, and you don't want that there. "/bin." != "/bin"
  • MattT
    MattT over 13 years
    I just caught a mistake in what I told you to add to .bash_profile. I left out the slash in front of the path. GO into .bash_profile and change the line to: export PATH=$PATH:/usr/local/mysql/bin