How to fix MySQL command not found error

Learn how to fix MySQL command not found error in Windows, macOS, and Linux

Posted on September 20, 2021

The mysql Command not found error occurs because your computer can’t find a program associated with the command on your computer’s PATH environment variable.

$ mysql
-bash: mysql: command not found

The PATH environment variable is a list of directories specifying where your computer should look for a program to run from the Terminal.

When you execute the mysql command from the Terminal, your computer will look through all the folders listed under PATH variable to find the mysql executable file and pass your commands to it.

The way to fix the error is to add MySQL bin/ folder to your PATH environment variable, but where the bin/ folder is located will be different depending on the Operating System you used on your Computer.

This tutorial will help you fix the error for Windows, macOS and Linux-based Operating Systems. Let’s start with Windows first.

Fix mysql command not found error in Windows

If you’re using Windows OS on your Computer, MySQL bin/ folder is usually located on C: drive as shown below:

C:\Program Files\MySQL\MySQL Server 8.0\bin

MySQL appends the installed version on the folder name, so if you installed another version of the MySQL server, then your path should have the version in the path as well.

For version 7, the path becomes MySQL Server 7.0\bin

Now the path above is only valid when you install MySQL using the official MySQL installer.

If you install MySQL using third-party applications like XAMPP or WAMP, then the location of the bin/ folder may be different.

For XAMPP, it may be located on XAMPP folder as follows:


You need to check your Computer to find the actual folder location.

Once you find your bin/ folder location, use the following steps to add the folder to your PATH environment variable:

Go to My Computer or This PC for Windows 10. Right-click on empty space and open the Properties window:

Click Advanced system settings from the left bar of the Properties window:

Now you’re in the System Properties window. Click the Environment Variables... button:

Now you’re in the Environment Variables window. Select the Path variable from either the User Variables or System Variables table and click on the Edit... button:

At the end of the variable values, add C:\Program Files\MySQL\MySQL Server 8.0\bin as a new entry to your Path variable:

Don’t forget to adjust the location of the bin/ folder if you’re using third-party installers.

Please enter the absolute path from the drive letter to your MySQL program’s bin/ folder.

Once done, click OK and open a new Terminal or Command Line window. If you’re calling mysql from the VSCode terminal, you need to restart VSCode first before trying again.

The mysql command not found error should be fixed and you should be able to check this using the mysql --version command:

$ mysql --version
mysql  Ver 8.0.26 for Win64 on x86_64 (MySQL Community Server - GPL)

And that’s how you fix the error on Windows.

Fix mysql command not found error in macOS

On macOS, you should be able to use mysql command once you installed MySQL using the official macOS installer or Homebrew.

If you find the command not found error, then you need to manually add the bin/ folder to your .bashrc or .zshrc file if you use ZSH command line client.

If you’re installing MySQL using the official installer, then your MySQL bin/ folder should be located on /usr/local/bin/mysql

But if you installed MySQL using Homebrew, then the bin/ folder may be located in the /usr/local/Cellar/mysql folder as shown below:


The most recent version of Homebrew installation will automatically create a symlink from /usr/local/bin/mysql to the Cellar/mysql folder.

But if you still can’t run mysql command, then you need to add the bin/ folder to the PATH variable manually.

To add bin/ folder to the PATH variable, open your .bashrc or .zshrc file and append the following export PATH statement on the last line:

export PATH=/usr/local/Cellar/mysql/8.0.26/bin:$PATH

You need to adjust the bin/ folder location above to your Computer’s actual location.

Now you should be able to run mysql commands from Mac’s Terminal.

Fix mysql command not found error in Linux

When you’re using a Linux-based Operating System like Ubuntu, the mysql command not found error usually comes with a guide to install the mysql-client-core application as shown below:

$ mysql

Command 'mysql' not found, but can be installed with:

sudo apt install mysql-client-core-8.0     # version 8.0.26-0ubuntu0.20.04.2, or
sudo apt install mariadb-client-core-10.3  # version 1:10.3.31-0ubuntu0.20.04.1

You just need to follow the instructions and install one of the two packages above. I recommend you use the official mysql-client-core package.

The mariadb-client-core package is for MariaDB database platform, which is a fork of MySQL.

Install the package using the sudo command as shown below:

sudo apt install mysql-client-core-8.0

You will be asked for your root password. Once the installation is completed, you should be able to run mysql commands from the Terminal:

$ mysql --version
mysql  Ver 8.0.26-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))

If you already installed mysql-client-core package but still found the MySQL command not found error, then your MySQL bin/ folder path may not be added to your PATH variable yet.

To fix the error, you can try to uninstall mysql-client-core package first:

sudo apt remove mysql-client-core-8.0

Then install it again:

sudo apt install mysql-client-core-8.0

If the error still appears, then you need to manually add the MySQL bin/ folder to your PATH variable.

You need to check manually where the bin/ folder is located. It’s commonly located in /usr/bin/ or /usr/local/bin/.

Once you find the bin/ folder, navigate to your home directory from the Terminal and open your .bashrc file using a text editor like nano:

cd ~ # navigate to home directory
nano .bashrc # open the file using nano text editor

Inside the .bashrc file, add an export PATH statement on the last line as follows:

export PATH=$PATH:/usr/bin

That should be enough to fix the error. Save your changes and restart your Terminal.

Now you should be able to access mysql command from Linux Terminal.

Related articles:

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.