Last updated: Apr 4, 2024
Reading timeยท6 min
The error "'mysql' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:
mysql
executable in your system's PATH
environment variable.NOTE: The first subheading in the article goes through the installation process for MySQL.
If you already have MySQL installed, click on the following link to scroll down
to the subheading about adding mysql.exe
to your PATH.
To install MySQL on Windows:
mysql-installer-web-community-X.Y.Z.msi
.web
in its name requires you to have an internet connection while running it, while the other installer can be run offline.If you have any missing manual requirements. you can either download them, install them and click on the "Check" button or click on "Next" to skip them.
On the next screen, click on the "Execute" button to download the products.
If downloading any of the products fails, you can click on the "Try Again" button next to its name to retry.
Once the Status column shows Downloaded for all products, click on the Next button.
Once the Status column shows Complete for all products, click on the Execute button.
Click on the "Next" button on the "Product Configuration" screen.
Leave the defaults selected on the "Type and networking" screen and click on the "Next" button.
On the "Product Configuration" page, click "Next".
Click Finish on the Installation Complete screen.
The next step is to add the path to the mysql
executable (mysql.exe
) to your
system's PATH environment variable.
The default path where the mysql.exe
file is stored should look like the
following.
C:\Program Files\MySQL\MySQL Server 8.0\bin # ๐๏ธ or Program Files (x86) C:\Program Files (x86)\MySQL\MySQL Server 8.0\bin
Note that the path contains the MySQL version number, so it will likely be different for you.
To add the path to the mysql
executable to your system's PATH environment
variable:
bin
directory or paste it directly.For me, the path is the following.
# ๐๏ธ Should be the default path C:\Program Files\MySQL\MySQL Server 8.0\bin # ๐๏ธ Or Program Files (x86) C:\Program Files (x86)\MySQL\MySQL Server 8.0\bin
Note that the path contains the MySQL version number, so it will likely be different for you.
mysql.exe
file because this is the file that is run when you issue mysql
commands.mysql
executable, add it and click on the
"OK" button twice to confirm.You might also have to restart your PC, but that's not always necessary.
Open a new CMD shell and issue the mysql -V
command to make sure the mysql
executable is accessible.
mysql -V
If the error persists, try to restart your PC to make sure you don't have any
stale CMD, PowerShell or IDE sessions and rerun the mysql -V
command.
You can use the mysql -u root -p
command to connect to the MySQL server.
mysql -u root -p
Note that you will be prompted for the password you entered during installation.
Use the SHOW DATABASES
command to show the available databases.
SHOW DATABASES;
There is a world
database that we can connect to.
First, use the exit
command to exit the server.
exit
Now use a connection scoped to the world
database.
mysql --host=localhost --user=root --password=YOUR_PASSWORD world
Make sure to replace the YOUR_PASSWORD
placeholder with your actual password.
Use the SHOW TABLES
command to list the tables in the database.
SHOW TABLES
Let's select the first 10 cities from the city
table.
SELECT * FROM city LIMIT 10;
To solve the "'mysql' is not recognized as an internal or external command, operable program or batch file" error, make sure:
mysql
executable in your system's PATH environment
variable.You can learn more about the related topics by checking out the following tutorials: