- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Fix MySQL 'Command Not Found' (Linux, Windows, mac OS)?
MySQL is a popular open-source relational database management system. It is widely used in web applications and provides efficient data storage and retrieval capabilities.
It is easy to install and configure on Linux, Windows, and mac OS systems. However, sometimes users encounter issues while using MySQL.
Explanation of the issue: 'Command Not Found'
The 'Command Not Found' issue arises when the user tries to execute MySQL commands but the system can't locate them. This error commonly occurs when the command was mistyped or inexistent package was installed or if the PATH environment variable isn't set up correctly.
Causes of 'Command Not Found' Error
MySQL is a free and open-source relational database management system that has been widely used in various applications. However, when you try to run MySQL, you might encounter the error message "Command Not Found," which means the system cannot find the command associated with it.
This error is commonly caused by incorrect installation or configuration, path issues, or missing dependencies.
Incorrect installation or configuration
This issue typically occurs when you try to install the wrong version of MySQL for your operating system or by following an incorrect installation procedure. This issue can lead to missing files and directories within the MySQL directory tree, making it difficult for your system to locate and execute MySQL commands.
The PATH variable defines where executable files are located on your filesystem so that users can execute them from any directory without specifying their full paths (i.e., /usr/bin/mysql instead of /usr/bin/mysql/mysql).
To troubleshoot this issue, confirm whether MYSQL_HOME environment variable has been set correctly; MYSQL_HOME should contain a path like "/usr/local/mysql", which points to the installed MySQL directory.
If not, you can set it using the following command −
Solutions for 'Command Not Found' Error in Linux
Checking if MySQL is installed
Before attempting to fix the 'Command Not Found' error, it is important to check whether MySQL is installed on your Linux machine. There are two ways to do this − using the command line or using a package manager.
Using the command line − Open a terminal window and enter the following command −
If MySQL is installed, you will see its version number displayed in the output.
If not, you will receive an error message indicating that the command cannot be found.
Using a package manager: Most Linux distributions come with a package manager that makes it easy to manage software installations and updates.
To check if MySQL is installed using a package manager, open a terminal window and enter the following command: For Debian/Ubuntu-based distributions −
dpkg -l | grep mysql-server
For Red Hat/Fedora-based distributions −
yum list installed | grep mysql-server
If MySQL is installed, you will see its name and version number displayed in the output. If not, you will receive an error message indicating that the package cannot be found.
Adding MySQL to PATH variable
Once you have confirmed that MySQL is installed on your Linux machine, you may still encounter the 'Command Not Found' error if its location is not included in your system's PATH variable. Here are two solutions for adding MySQL to your PATH −
Temporary solution − Open a terminal window and enter the following command −
This adds /usr/local/mysql/bin (the default installation directory for MySQL on Linux machines) to your system's PATH variable for the current terminal session only.
If you close the terminal window or open a new one, you will need to enter this command again.
Permanent solution: To add MySQL to your system's PATH variable permanently, follow these steps−
Open the .bashrc file in your home directory using any text editor of your choice (e.g. nano, vim, gedit).
Add the following line at the end of the file −
This adds /usr/local/mysql/bin to your system's PATH variable every time you open a terminal session.
Save and close the file.
To apply the changes immediately without having to log out and back in again, enter the following command in your terminal −
Solutions for 'Command Not Found' Error in Windows
Checking if MySQL is Installed
If you are experiencing a 'Command Not Found' error in Windows, the first step is to check if MySQL is installed on your system or not. Here are two methods to do so: Using the Command Prompt −
Press Windows Key + R.
Type 'cmd' and hit enter.
In the command prompt, type 'mysql -V' and hit enter.
If MySQL is installed, it will display the version number.
Using Control Panel
Click on the Start menu and select 'Control Panel'.
In Control Panel, select 'Programs' > 'Programs and Features'.
Look for MySQL in the list of programs displayed.
If MySQL is installed, it will be listed along with its version number.
Adding MySQL to PATH Variable
Once you have confirmed that you have MySQL installed on your Windows system, adding it to your PATH variable can help resolve the 'Command Not Found' error. Note: Before proceeding with this solution, make sure you know how to access environment variables in Windows. Here are two ways to add MySQL to your PATH variable −
Method 1 - Temporary Solution:
Open Command Prompt.
Type 'set path=%path%;C:\Program Files\MySQL\MySQL Server 8.x\bin'(Replace 8.x with your version number).
Ensure that the path was added correctly by typing 'echo %path%'.
Method 2 - Permanent Solution:
Go to Start menu and search for 'Environment Variables'.
Click on 'Edit the system environment variables'.
Click on 'Environment Variables' button.
Under 'System Variables', scroll down to find the Path variable and click on Edit.
Click on New and add 'C:\Program Files\MySQL\MySQL Server 8.x\bin'(Replace 8.x with your version number).
Click OK to close all dialog boxes.
Solutions for 'Command Not Found' Error in mac OS
Mac OS users may also face the 'command not found' error when attempting to use MySQL. Here are some solutions −
Checking if MySQL is installed
The first step to fixing the 'command not found' error on a Mac OS is checking if MySQL is installed. You can do this using the terminal or a package manager.
To check if MySQL is installed using the terminal −
Type “mysql -V” and press enter.
If you get a message with version information, then MySQL is installed on your Mac OS.
If you get an error message such as “command not found,” then you need to install it first before continuing with the next steps.
Using Package Manager
You can also check if MySQL is installed using a package manager such as Homebrew −
Type "brew info mysql" and press enter.
If you see information about the installation, then it’s already installed, otherwise install it by running "brew install mysql".
Adding MySQL to PATH variable
The next step to fixing the 'command not found' error on a Mac OS after installation is adding MySQL to PATH variable −
Type "nano ~/.bash_profile" into your command prompt and press Enter. This will open up your .bash_profile file in nano text editor.
Note −: If this file doesn't exist, create one by typing touch ~/.bash_profile into your command prompt and press Enter.
At the end of the file, add the following line: export PATH="/usr/local/mysql/bin:$PATH"
Type “control + o” to save changes and “control + x” to exit nano text editor.
Reload the file by running “source ~/.bash_profile.”
By adding MySQL to PATH variable, you make it possible for your terminal to locate its executables. You will no longer receive 'command not found' error while using MySQL on Mac OS.
Fixing the "Command Not Found" error in MySQL requires attention and patience during setup procedures. While it may seem daunting at first glance, understanding basic troubleshooting techniques such as typos prevention and checking system requirements will help alleviate these issues swiftly.
Kickstart Your Career
Get certified by completing the courseGet Started