How to Fix MySQL Command Not Found on Windows
You probably stumbled upon one of these two errors:
bash: mysql: command not found error when you tried to run a MySQL command from the bash terminal
‘mysql’ is not recognized as an internal or external command, operable program or batch file error when you tried to run a MySQL command from the Command Prompt
You’ve come to the right place because in this post I’m going to walk you through simple steps you can take to fix the MySQL command not found error on a Windows machine.
The source of the errors
The error occurs because Windows can’t find the MySQL program, even though it’s probably already installed on your system.
To fix this, we need to add the MySQL executable to the PATH environment variables.
Let’s do that.
Fix the errors
Open up the search bar and search for “env” then open up Edit the system environment variables.
Then go to Environment Variables -> select Path -> click Edit -> then New and then add the path to the MySQL \bin folder.
You’d have to decide if you want to add MySQL only for the current user, which in my case is Carol.
Or you want MySQL to be globally available for any users using your machine.
If you’re using the MySQL Server, then most likely the path is C:\Program Files\MySQL\MySQL Server 8.0\bin.
In my case, I’m using XAMPP so the path is C:\xampp\mysql\bin
As soon as you’re done editing, click OK, OK then apply and then try and run any MySQL commands.
If you’re using Git Bash in VS Code as I do, you’ll have to restart VS Code first because it’s currently unaware of the new system variable we just added.
If you’re using Command Prompt, it should be able to work without restarting it.