This article explains resolving the “MySQL command Not Found” error. This error usually means that MySQL is not installed on your system or its installation path is missing from the system’s PATH environment variable.
Follow the steps below:
- Understanding the Error
If you encounter the “MySQL command not found” error when executing MySQL from the command line, it clearly indicates that the system cannot locate the MySQL executable in the directories listed in the PATH environment variable. As a result, you may need to verify the installation or update the PATH variable accordingly. This issue often arises in new installations or switching between multiple MySQL versions. - Verifying MySQL Installation:
- Start by checking if MySQL is installed by running the following command in your terminal:
mysql --version
- If MySQL is installed, this command will display its version. If not, you want to install MySQL.
- Start by checking if MySQL is installed by running the following command in your terminal:
- Installing MySQL:
- For Linux:
sudo apt-get update sudo apt-get install mysql-server
- For macOS:
brew install mysql
- For Windows:
Download the MySQL installer from the official website and follow the steps in the installation wizard.
- For Linux:
- Updating the PATH Environment Variable:
If MySQL is installed but still not recognized, add its directory to the PATH environment variable.- For Linux and macOS:
- Find the MySQL installation path:
which MySQL
- Add the MySQL bin directory to your profile script (e.g., .bashrc or .zshrc):
echo ‘export PATH="/path/to/mysql/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
Replace /path/to/mysql/bin with the actual MySQL path.
- Find the MySQL installation path:
- For Windows:
- Open the Start menu, search for “Environment Variables,” and select it.
- Under “System Variables,” edit the Path variable.
- Add the path to the MySQL bin directory and save the changes.
- For Linux and macOS:
- Confirming the Fix
After installing MySQL or updating the PATH variable, repeat the following command to confirm:mysql --version
If the setup is correct, this command should now display the MySQL version.
- Troubleshooting Persisting Issues
If the issue persists, consider these steps:- Ensure that you have the essential permissions to access MySQL.
- Double-check for typos in the PATH variable.
- Restart your terminal or system to apply the changes.
By following these steps, you should be able to resolve the “MySQL Command Not Found” error and successfully use MySQL from the command line.
Need help managing MySQL users? Check out our guide on How to Add a User to a MySQL Database