How to Fix MySQL 'Command Not Found' in Linux, Windows & macOS


MySQL is an open-source database management system that runs on Windows, Linux, and macOS. The Command Not Found error occurs when the system cannot start the MySQL service because it is unable to find the executable file.

This article shows how to fix the MySQL Command Not Found error in Windows, Linux, and macOS.

How to Fix MySQL Command Not Found Error


  • A Windows, Linux, or macOS system with an administrator account.
  • A local MySQL installation.

What Causes 'Command Not Found' in MySQL?

When running the command to start the MySQL interface, the system searches its directories for the MySQL binary to execute.

The Command Not Found error indicates the system was not able to locate the binary you want to run. The most common reasons for this error are:

  • Corrupt MySQL installation. In some instances, the MySQL installation is corrupted. If that is the case, a fresh MySQL installation is necessary.

Note: If you need assistance with installing MySQL, check these tutorials on how to install MySQL on Ubuntu 22.04 or Windows.

  • The PATH environment variable has not been set. If the installation is not corrupted and MySQL is active and running, the binary might not be added to the system PATH. The PATH variable lists all the directories the system looks through. If the system can't find the binary in any directory in the defined PATH, then it displays the Command Not Found error.

The following sections outline how to set the PATH environment variable in Windows, Linux, and macOS.

Note: The MySQL Command Not Found error manifests in different ways depending on the operating system.

How to Fix MySQL 'Command Not Found' Error in Windows

Start the Windows command (cmd) prompt and enter the command to launch MySQL:

mysql -u root -p
mysql -u root -p Windows

If the system cannot to execute the command, it shows the mysql is not recognized as an internal or external command error. Follow the steps below to fix the issue:

1. Navigate to the Windows Start Menu.

2. Select This PC and click the Properties tab.

3. Select Advanced system settings.

Advanced system settings on a PC

4. Click the Environment Variables... button.

Environment variables

5. Click the Path system variable and then the Edit... button.

edit PATH

6. Select New to add the correct path for the MySQL folder.

add new variable

7. Retrieve the full MySQL installation path. In this example, MySQL is on the C partition in the Program Files folder. Find the bin folder within MySQL and copy the path.

Find MySQL  bin folder

8. Paste the full path to the Edit environment variable window, click OK to save the changes, and exit the screen.

paste path to MySQL

9. Restart the command prompt interface and enter the initial command once again:

mysql -u root -p
terminal output for mysql -u root- -p

You have successfully logged in to the MySQL shell.

How to Fix MySQL 'Command Not Found' Error in Linux

This section shows what actions to take to fix the Command Not Found error on Linux.

Start MySQL with:

mysql -u root -p
mysql -u root -p terminal output in Linux

If the output prints the Command 'mysql' not found error, follow these steps.

1. Run the echo $PATH command. The PATH variable contains a list of directories where the system looks for executable files when you type a command.

echo $PATH
echo $PATH terminal output in Ubuntu

The MySQL installation directory is not on the list.

2. To add the MySQL directory path, open the .bash_profile file. Use your preferred text editor (e.g., Nano) to edit the file:

nano .bash_profile

3. Add a line at the end of the file that specifies the MySQL directory location:

export PATH=$PATH:[/home/location/of/mysql/bin/folder]

In this example, the MySQL directory location is /usr/bin/mysql.

export PATH=$PATH:/usr/bin/mysql.
Edit bash_profile file

Note: To verify the location of the MySQL directory, run which mysql.

4. Save and exit the file.

5. Run the following command to launch MySQL:

mysql -u root -p
mysql -u root -p terminal output Linux

You have successfully accessed MySQL on Linux.

How to Fix MySQL 'Command Not Found' Error on macOS

The same principle discussed for Windows and Linux applies to macOS. The error appears across different operating systems due to the misconfigured PATH variable. The system is unable to find executable files in the directories it searches. The error in macOS looks like this:

mysql -u root -p terminal output for macOS

To fix the error, take the following steps:

1. Edit the .bash_profile file on macOS by entering the following command:

open -t .zprofile

2. Add the path to the MySQL bin directory. In this case, it is:

export PATH=${PATH}:/usr/local/mysql/bin
Export PATH in mac

3. Save and exit the file.

4. Enter this command to access the MySQL monitor:

mysql -u root -p
mysql -u root -p terminal output for macOS no error

You have successfully gained access to the MySQL shell.


After reading this article, you now know how to fix the Command Not Found error. This tutorial covered the three major operating systems.

Next, learn how to deal with the 'Access Denied For User Root@Localhost' error which usually appears for new installations of MySQL when you try to connect as the root user.

Was this article helpful?
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
How to List All Users in a MySQL Database
November 18, 2019

This simple tutorial analyses the commands used to list all user accounts in MySQL. Learn about additional...
Read more
How To Create New MySQL User and Grant Privileges
September 18, 2019

MySQL is a database application for Linux. It's part of the LAMP (Linux, Apache, MySQL, PHP) stack that...
Read more
How To Show a List of All Databases in MySQL
October 13, 2022

With Structured Query Language (SQL), you can easily access and manage content in all your databases. This...
Read more
How to Import and Export MySQL Databases in Linux
March 11, 2024

MySQL is a versatile application. It can be used for something as simple as a product database, or as complex...
Read more