'mysql' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
6 min

banner

# 'mysql' is not recognized as an internal or external command

The error "'mysql' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:

  1. Not having MySQL installed on your Windows machine.
  2. Not having the path to the mysql executable in your system's PATH environment variable.

mysql is not recognized as internal or external command

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:

  1. Download the MySQL Installer for Windows by clicking on the "Download" button for the mysql-installer-web-community-X.Y.Z.msi.

download mysql installer

The installer that contains web in its name requires you to have an internet connection while running it, while the other installer can be run offline.
  1. If you get redirected to a different page, click on the "No thanks, just start my download." link.

start mysql download

  1. When you start the installer, you might have to change your app recommendation settings.

change my app recommendation settings

  1. You can set the "Choose where to get apps" value to "Anywhere, but warn me before installing an app that's not from the Microsoft Store".

choose where to get apps

  1. Click on "Install anyway".

click install anyway

  1. On the "Choosing a Setup Type" screen, click on the "Full" radio button to install all included MySQL features and click "Next".

click full radio button

  1. 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.

  2. On the next screen, click on the "Execute" button to download the products.

click execute to download 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.

  1. Click on the "Execute" button to install the products you downloaded.

click execute to install products

Once the Status column shows Complete for all products, click on the Execute button.

  1. Click on the "Next" button on the "Product Configuration" screen.

  2. Leave the defaults selected on the "Type and networking" screen and click on the "Next" button.

type and networking defaults

  1. Leave the default "Authentication Method" selected and click on the "Next" button.

default authentication method

  1. Set your Root account password, make sure to remember it and click "Next".

set password for mysql

  1. Leave the defaults selected on the "Windows Service" screen and click "Next".

windows service select defaults

  1. Leave the default of "grant full access to the user" selected on the "Server File Permissions" screen and click "Next".

server file permissions select defaults

  1. Click on the "Next" button on the "Apply Configuration" screen.

apply configuration

  1. Once the configuration for MySQL Server is complete, click on the "Finish" button.

mysql configuration complete

  1. Click on the "Next" button to proceed to the "MySQL Router" configuration.

configure mysql router

  1. Leave the defaults selected on the MySQL Router Configuration screen and click on Finish.

mysql router leave defaults selected

  1. In the "Product Configuration" page, click "Next" to proceed to the "Samples and Examples" configuration page.

proceed samples and examples

  1. On the "Connect to Server" screen, enter the password that you previously entered in the Password field, click on the Check button to verify and click Next.

connect to server

  1. On the "Apply Configuration" screen, click on the Execute button.

apply configuration click execute

  1. Once the configuration has been completed, click Finish.

configuration complete

  1. On the "Product Configuration" page, click "Next".

  2. Click Finish on the Installation Complete screen.

installation complete click finish

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.

shell
C:\Program Files\MySQL\MySQL Server 8.0\bin # ๐Ÿ‘‡๏ธ or Program Files (x86) C:\Program Files (x86)\MySQL\MySQL Server 8.0\bin

path to mysql executable

Note that the path contains the MySQL version number, so it will likely be different for you.

# Add the path to mysql.exe to your System's PATH environment variable

To add the path to the mysql executable to your system's PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, select the "Path" variable and click "Edit".

select path and click edit

  1. You can either click "New" and then "Browse" and navigate to the path of the bin directory or paste it directly.

click new browse

For me, the path is the following.

shell
# ๐Ÿ‘‡๏ธ 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

path to mysql executable

Note that the path contains the MySQL version number, so it will likely be different for you.

We are looking for the directory that contains the mysql.exe file because this is the file that is run when you issue mysql commands.
  1. Once you find the path to your mysql executable, add it and click on the "OK" button twice to confirm.

added path to mysql exe

  1. Close your Command Prompt and then reopen it.
Note that you must restart your Command prompt shell for the changes to take effect.

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.

cmd
mysql -V

mysql-command-works

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.

cmd
mysql -u root -p

mysql connect to server

Note that you will be prompted for the password you entered during installation.

Use the SHOW DATABASES command to show the available databases.

cmd
SHOW DATABASES;

mysql show databases command

There is a world database that we can connect to.

First, use the exit command to exit the server.

cmd
exit

Now use a connection scoped to the world database.

cmd
mysql --host=localhost --user=root --password=YOUR_PASSWORD world

Make sure to replace the YOUR_PASSWORD placeholder with your actual password.

connect to world database

Use the SHOW TABLES command to list the tables in the database.

cmd
SHOW TABLES

show tables command

Let's select the first 10 cities from the city table.

cmd
SELECT * FROM city LIMIT 10;

select records from city database

# Conclusion

To solve the "'mysql' is not recognized as an internal or external command, operable program or batch file" error, make sure:

  1. You have MySQL installed on your Windows machine.
  2. You have the path to the mysql executable in your system's PATH environment variable.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev