Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run mysql from the command line on mac?

Tags:

mysql

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

like image 301
zok Avatar asked Dec 20 '22 15:12

zok


2 Answers

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"

like image 154
Trent Lloyd Avatar answered Jan 13 '23 15:01

Trent Lloyd


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.
like image 21
saqehi Avatar answered Jan 13 '23 15:01

saqehi