When trying to access MySQL using the Windows command line, you may get the
mysql is not recognized error as shown below:
> mysql 'mysql' is not recognized as an internal or external command, operable program or batch file.
This kind of error happens when Windows operating system doesn’t know what to do with the
mysql command that you want to run.
To fix the error, you need to make sure that the
mysql.exe file is available under your
mysql.exe file is located on the
bin/ folder of your MySQL program, but the location of your MySQL program will depend on what program you use to install MySQL on your computer.
If you used the official MySQL server installer, then your
bin/ folder should be located on the following path:
C:\Program Files\MySQL\MySQL Server 8.0\bin
Notice the server version is used as the folder name in the path above as
MySQL Server 8.0. 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
If you didn’t install MySQL server using the official installer, then you need to find where exactly that the MySQL program is installed on your computer.
If you’re using a third-party installer like XAMPP or WAMP, then the location of your MySQL installation could be in the path to the said software.
For example, I installed XAMPP on
D:\XAMPP so the MySQL server is installed on
Once you found the location of the MySQL
bin/ folder, you can add a new entry to the Windows
PATH environment variable in two ways:
- Using the Command Prompt
- Using the Windows graphical UI
The Command Prompt allows you to set the PATH variable for the current session by using the
SET PATH command.
SET PATH=%PATH%;<your mysql bin folder location>
You need to replace
<your mysql bin folder location> with the actual location of the
Here’s an example from my computer:
SET PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 8.0\bin
Now you should be able to run
mysql command from the command line.
SET PATH command only works temporarily, meaning that once you exit the command line, you need to set the path again.
If you want to add the MySQL
bin/ folder permanently, then you need to use the Windows graphical UI.
Fix MySQL not recognized error using Windows Graphical UI
To add the
bin/ folder location permanently, you need to do the following steps:
First, 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
At the end of the variable values, add
C:\Program Files\MySQL\MySQL Server 8.0\bin as a new entry to your
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
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.
mysql is not recognized 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)
Now you should be able to login and run other
mysql related commands from the command line. Nice work!