Using MySQL Client With MySql Server Or MAMP — Run MySQL via Command Line ( CLI )

Imran Sayed
3 min readNov 6, 2021

In this blog, we will learn about how we can use the MySql client in the terminal to execute MySQL commands.

We will discuss two scenarios of using MySQL client:

  1. With MAMP
  2. With MySQL Server.

The key task after installing one of the above would be to just provide the PATH where MySQL is installed in your .bash_profile or .zshrc file.

1. With MAMP

MAMP Already has the MySQL Server.
You can download the MAMP and find the basic information like MySQL port number on the MAMP App.

Using MySQL client on Command Line

Once it’s downloaded, you can start the MAMP server from the above tool and then add the path of the MySQL installation in your .bash_profile file or .zshrc ( if you are using OhMyZsh ):

export PATH="/Applications/MAMP/Library/bin:$PATH"

Note: To find your .bash_profile ( create it if it does not exist ) or .zshrc, go to the root directory in your terminal and type ls -al

Then,

nano .bash_profile

or

nano .zshrc

Explanation — The reason we add the PATH where MySQL is installed so that we can run MySQL using mysql command, rather than having to type the full path like /Applications/MAMP/Library/bin/mysql — host=localhost -uroot -proot.

Now, save the bash file and restart the terminal. Now you can access MySQL by running:

mysql --host=localhost -uroot -p

It will prompt you to put the password, which is usually blank unless you have changed it. For instance, in my case I have see the password as root.

2. With MySQL Server

MySQL Server is often used with MySQL Workbench
First, we install and set up a MySQL server using this link. Make sure to download x86, 64-bit one from the list.

Follow this process to install it. Make sure to select custom installation.

Also, Configure your password. Please make a note of this six-digit password.

Then go to system preference and click on MySQL dolphin icon.

It will look something like this:

Click on Configuration tab to see where your MySQL is installed.

In this case, it’s /usr/local/mysql

Running MySQL Client on Terminal

Add the path of the MySQL installation in your .bash_profile file or .zshrc ( if you are using OhMyZsh ):

export PATH="/usr/local/mysql/bin:$PATH"

Save the bash file and restart the terminal. Now you can access MySQL by running:

mysql -u root -p

It will prompt you to put the password. Please make sure to use the same password that you had put at the time of custom installation of the MySQL Server.

You can learn more about MySQL here.

That’s all folks.

--

--

Imran Sayed

👤 Full Stack Developer at rtCamp, Speaker, Blogger, YouTuber, Wordpress, React, Node, Laravel Developer http://youtube.com/ImranSayedDev