6

I want to run MYSQL from the command line, as in

mysql -u root -p

but it returns

-bash: mysql: command not found

So, need to install it, I think. But then what application exactly do I need to install? I see a dozen applications here: http://dev.mysql.com/downloads/, installed some, but still can't use mysql from the command line.

I'm using mavericks. Thanks a lot

2
  • 1
    I'd just go with a Vagrant box. Installing server software on your dev box is always a pain, especially on a mac Commented May 6, 2014 at 3:29
  • 1
    I'd second Phil's recommendation about Vagrant, but if you must have MySQL on your Mac, try here: machiine.com/2013/… Commented May 6, 2014 at 3:31

2 Answers 2

11

MySQL does not separate the server and client downloads, so you basically just need to download the entire MySQL version -- while it will download the binaries for the server it won't actually start or set-up a server unless you explicitly intend to.

You can go to the download URL (http://dev.mysql.com/downloads/mysql/) and select "Mac OS X" from platform and download "Mac OS X 10.7 (x86, 64-bit), DMG Archive"

The default MySQL installation installs to /usr/local/mysql which is not in your path, specifically the MySQL client is installed at /usr/local/mysql/bin/mysql

You can specify it exactly to launch the client:

/usr/local/mysql/bin/mysql -u root

If you would like a GUI client I can highly recommend "Sequel Pro" or "MySQL Workbench"

Sign up to request clarification or add additional context in comments.

1 Comment

Trent is right. It's worth mentioning as well that you could use MAMP.... if your needs are short term, just use that (or SQLite). If you need to run MySQL on your Mac (which frankly seems a bit unlikely) Trent's response is very good.
4

I'll give you a workaround to achieve your wishes...

  1. Create a script to run the specific path for you, lets call it connect_to_my_sql.c:
  #include <stdlib.h>
  int
  main() {
    system("/usr/local/mysql/bin/mysql -u root");
  }
  1. Compile your C script:
  gcc -o mysql connect_to_my_sql.c
  1. Move your binary file (i.e. your mysql file) to a folder in your path:
  mv mysql /usr/local/bin
  1. Now, you should be able to run MySQL by typing mysql everywhere from the terminal.

Alternatively, create an Alias like so:

  1. Open your ~/.bash_profile
  vi ~/.bash_profile
  1. Add following line to your bash_profile:
  alias mysql="/usr/local/mysql/bin/mysql -u root"
  1. Source your bash_profile
  source ~/.bash_profile
  1. Should be able to run MySQL by typing mysql everywhere from the terminal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.