How do I install command line MySQL client on mac?

MysqlMacosTerminal

Mysql Problem Overview


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.

Mysql Solutions


Solution 1 - Mysql

install MySQLWorkbench, then

export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS

Solution 2 - Mysql

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/

Solution 3 - Mysql

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

Solution 4 - Mysql

Best option is:

brew install mysql

Solution 5 - Mysql

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.

Solution 6 - Mysql

There is now a mysql-client formula.

brew install mysql-client

Solution 7 - Mysql

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

Solution 8 - Mysql

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

Solution 9 - Mysql

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.

Solution 10 - Mysql

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 '[email protected]: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`.

Solution 11 - Mysql

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)"

Solution 12 - Mysql

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)

Solution 13 - Mysql

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.

Solution 14 - Mysql

The mysql client is available in macOS ports. If you don't have this excellent third party package manager already installed, it is available from here: https://www.macports.org/

Once you have installed macports, open a terminal and make sure everything is up to date:

sudo port selfupdate

There are multiple different versions of MySQL and mariadb (community fork of MySQL) available in the ports repos. List available versions using the following command:

port search 'mariadb*'

I recommend choosing mariadb over mysql as it is, mostly, a drop in replacement (https://mariadb.com/kb/en/mariadb-vs-mysql-compatibility/) and has excellent community support.

If applicable, choose which version of mariadb you want (a list of versions of mariadb is available here: https://downloads.mariadb.org/mariadb/+releases/). If you're not bothered, install the default version:

sudo port install mariadb

Mariadb (including the mysql-compatible command line client) is now available on your system. On my system, the CLI client resides in the following location:

$ /opt/local/bin/mysql --version
/opt/local/bin/mysql  Ver 15.1 Distrib 5.5.68-MariaDB, for osx10.15 (x86_64) using readline 5.1

It's obviously a bit inconvenient to type out the full path, /opt/local/bin/mysql each time you want to use the client. Ports has already thought of this problem. To view available versions of mysql on your system, run:

$ port select mysql

Available versions for mysql:
mariadb (active)
none

Choose one from the list. For example, to use mariadb as the default mysql client:

sudo port select mysql mariadb

Now open a fresh terminal window and you should be able to start the mariadb mysql CLI client:

mysql -h <hostname> -u <username> -p

Solution 15 - Mysql

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhchView Question on Stackoverflow
Solution 1 - Mysqluser1659189View Answer on Stackoverflow
Solution 2 - MysqlJackSparrowView Answer on Stackoverflow
Solution 3 - MysqlAlex WView Answer on Stackoverflow
Solution 4 - MysqlGeekView Answer on Stackoverflow
Solution 5 - MysqltrosemanView Answer on Stackoverflow
Solution 6 - MysqlegzeView Answer on Stackoverflow
Solution 7 - MysqlMichael LihsView Answer on Stackoverflow
Solution 8 - MysqlcaccialdoView Answer on Stackoverflow
Solution 9 - MysqlPaul KenjoraView Answer on Stackoverflow
Solution 10 - MysqlshashankSView Answer on Stackoverflow
Solution 11 - MysqlKimmo HintikkaView Answer on Stackoverflow
Solution 12 - MysqlAlex GView Answer on Stackoverflow
Solution 13 - MysqlWillaView Answer on Stackoverflow
Solution 14 - MysqlMarkView Answer on Stackoverflow
Solution 15 - MysqlLandiLeiteView Answer on Stackoverflow