I want to install the MySQL client for the command line, not a GUI. I have searched over the web but only found instructions on installing the MySQL server.
install MySQLWorkbench, then
export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS
-
5How can this be the accepted answer this only works for one session and has to be redone for every single session. (and yes I tried that restarting thing but that didn't work) – jonalv Dec 5 '16 at 13:08
-
5@jonalv Because shell commands can easily be added to one's .bashrc or .bash_profile if one desires any command (such as this one) to be run in every shell on startup. – jdunk Dec 26 '16 at 12:55
-
66How can this be the accepted answer when the question states "Not any GUI"? – Josh J Jan 30 '17 at 18:21
-
7Add the line in this answer to ~/.bash_profile and then run
source ~/.bash_profile
or load a new instance of terminal. – Luke Jan 15 '18 at 7:15 -
5You're taking this too far. You get a GUI and a CLI. Just use the CLI. Put it in your bash rc and you're done. – duality_ Aug 31 '18 at 9:00
If you have already installed MySQL from the disk image (dmg) from http://dev.mysql.com/downloads/), open a terminal, run:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
then, reload .bash_profile
by running following command:
. ~/.bash_profile
You can now use mysql
to connect to any mysql server:
mysql -h xxx.xxx.xxx.xxx -u username -p
Credit & Reference: http://www.gigoblog.com/2011/03/13/add-mysql-to-terminal-shell-in-mac-os-x/
-
4The OP implied that he did not want to install the server, just the command-line client. – Greg Brown Mar 1 '16 at 18:17
-
@JackSparrow You should have read the question first. You answer requires or implies installing mysql server but the question specifically said he did not want to install the server – Joseph Jul 17 '16 at 21:36
-
Thanks for the answer. The installer should do that kind of stuff. – Agustí Sánchez May 20 '17 at 0:27
Best option is:
brew install mysql
-
12
-
76
brew install caskroom/cask/mysql-shell
will install the command line client. – Krystian Dec 18 '17 at 15:43 -
26It might be worth mentioning that, if installed this way, the shell is launched with the
mysqlsh
command. – Eric Jorgensen Jan 25 '18 at 3:28 -
3Thank you @Krystian & @eric-jorgensen I modified command to
brew install Caskroom/cask/mysql-shell
cap C for "caskroom" and command used was mysqlsh from – il0v3d0g Mar 29 '20 at 20:48 -
2@Krystian: You should have posted your comment as an answer. +1 for that comment anyway. My MacOS Mojave 10.14.6, needed to run the command
brew install homebrew/cask/mysql-shell
instead. – Romeo Sierra Oct 7 '20 at 9:05
This strictly installs a command line client, without the other overhead:
Install Homebrew (if you don't have it):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then, install mysql-client
:
brew install mysql-client
Then, add the mysql-client
binary directory to your PATH:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
Finally, reload your bash profile:
source ~/.bash_profile
Then you should be able to run mysql
in a terminal, if not try opening a new terminal
-
Use
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
if using default zsh (default in recent macOS) – Jonny Jul 24 '20 at 13:18 -
1If you use zsh instead of bash you should add
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
to your~/.zprofile
file. – bounav Sep 14 '20 at 15:16
Mysql has a client-only set of utilities:
Mysql client shell https://dev.mysql.com/downloads/shell/
Other command line utilities https://dev.mysql.com/downloads/utilities/
Mac OSX version available.
-
3This is the closest to the right answer, considering the OP wanted client only and command line. However, user16... and @JackSparrow gave the most useful instructions on what to do after install. – Mike Williamson Jul 19 '17 at 21:20
-
-
3looks like they broke it out as a separate tool, dev.mysql.com/downloads/shell – troseman Oct 6 '17 at 7:39
-
MySQL Shell installs
mysqlsh
which seems to be an equivalent to the classicalmysql
command. You may install it with Homebrew usingbrew cask install mysql-shell
. – Bernhard Fürst Nov 21 '17 at 13:09 -
3If you're expecting a
mysql
prompt, trymysqlsh --sql
for a similar experience (and it takes mostly the same arguments, helpfully!) – Lorna Mitchell Dec 29 '17 at 11:56
There is now a mysql-client
formula.
brew install mysql-client
-
6It does install mysql command as something like
/usr/local/Cellar/mysql-client/x.x.x/bin/mysql
, which is probably not on PATH. Doingbrew link mysql-client
afterwards worked for me. – alx Jun 8 '19 at 13:25 -
2
For installing mysql-shell
with homebrew, run
brew cask install mysql-shell
you can then launch the mysql shell with
mysqlsh
if you want to enter SQL mode directly, run
mysqlsh --sql
Open the "MySQL Workbench" DMG file and
# Adjust the path to the version of MySQL Workbench you downloaded
cp "/Volumes/MySQL Workbench 6.3.9.CE/MySQLWorkbench.app/Contents/MacOS/mysql" /usr/local/bin
# Make sure it's executable
chmod +x /usr/local/bin/mysql
Eject the DMG disk
-
2This is how I solved the problem by the light your answer shed. Thanks.
cp /Applications/MySQLWorkbench.app/Contents/MacOS/mysql /usr/local/bin
– zzxwill Nov 9 '17 at 9:01 -
I would recommend using a soft link:
ln -s /Applications/MySQLWorkbench.app/Contents/MacOS/mysql /usr/local/bin
so that updates are reflected without having to run the copy again. – David Weber May 28 '18 at 15:36
If you installed from the DMG on a mac, it created a mysql client but did not put it in your user path.
Add this to your .bash_profile
:
export PATH="/usr/local/mysql/bin:$PATH
This will let you run mysql
from anywhere as you.
-
This worked for me. I installed the MySQL Shell from the MySQL website but still nothing. Fixing the path as directed above did the job. It seems the install did work, but didn't set the path correctly (if at all). – James Smith Dec 29 '17 at 17:48
Installation command from brew:
$ brew cask install mysql-shell
Look at what you can do:
$ mysqlsh --help
Run query from mysqlsh
client installed:
$ mysqlsh --host=192.x.x.x --port=3306 --user=user --password=xxxxx
MySQL Shell 8.0.18
Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a session to 'user@192.x.x.x:3306'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 16
Server version: 8.0.18 MySQL Community Server - GPL
No default schema selected;
type \use <schema> to set one.
MySQL 192.x.x.x:3306 ssl JS >
MySQL 192.x.x.x:3306 ssl JS > `\use rafdb`
Default schema set to `rafdb`.
As stated by the earlier answer you can get both mysql server and client libs by running
brew install mysql
.
There is also client only installation. To install only client libraries run
brew install mysql-connector-c
In order to run these commands, you need homebrew package manager in your mac. You can install it by running
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The easiest way would be to install mysql server or workbench, copy the mysql client somewhere, update your path settings and then delete whatever you installed to get the executable in the first place.
Using MacPorts you can install the client with:
sudo port install mysql57
You also need to select the installed version as your mysql
sudo port select mysql mysql57
The server is only installed if you append -server
to the package name (e.g. mysql57-server
)
if you need a lighter solution i recommend mysql-shell, install using the command below.
brew cask install mysql-shell
To start after installation type mysqlsh.
brew install mysql-client
– Ivan Mar 11 '19 at 7:53