Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Fix MySQL \'Command Not Found\' (Linux, Windows, mac OS)?
MySQL is a popular open-source relational database management system widely used in web applications for efficient data storage and retrieval. While it's straightforward to install on Linux, Windows, and macOS, users sometimes encounter the "Command Not Found" error when trying to execute MySQL commands.
Understanding the "Command Not Found" Error
The "Command Not Found" error occurs when the system cannot locate MySQL executable files. This typically happens due to:
Incorrect installation MySQL wasn't installed properly or completely
PATH issues MySQL's bin directory isn't included in the system's PATH variable
Wrong installation location MySQL was installed in a non-standard directory
Missing dependencies Required components weren't installed
The PATH environment variable tells the system where to look for executable files. If MySQL's location isn't in PATH, you must specify the full path to run MySQL commands.
Solutions for Linux
Check MySQL Installation
First, verify if MySQL is installed on your system:
mysql --version
If MySQL is installed, this displays the version number. Otherwise, check using your package manager:
# For Ubuntu/Debian dpkg -l | grep mysql-server # For Red Hat/CentOS/Fedora rpm -qa | grep mysql-server
Add MySQL to PATH Variable
Temporary solution (current session only):
export PATH=$PATH:/usr/local/mysql/bin
Permanent solution:
# Open .bashrc file nano ~/.bashrc # Add this line at the end export PATH=$PATH:/usr/local/mysql/bin # Apply changes source ~/.bashrc
Solutions for Windows
Check MySQL Installation
Verify MySQL installation using Command Prompt:
mysql --version
Or check through Control Panel ? Programs ? Programs and Features for MySQL entries.
Add MySQL to PATH Variable
Temporary solution:
set PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 8.0\bin
Permanent solution:
Search for "Environment Variables" in Start menu
Click "Edit the system environment variables"
Click "Environment Variables" button
Under "System Variables," find and edit "Path"
Click "New" and add:
C:\Program Files\MySQL\MySQL Server 8.0\binClick OK to save changes
Solutions for macOS
Check MySQL Installation
Check if MySQL is installed:
mysql --version
Or using Homebrew:
brew info mysql
Add MySQL to PATH Variable
Edit your shell profile file:
# For bash users nano ~/.bash_profile # For zsh users (macOS Catalina and later) nano ~/.zshrc # Add this line export PATH="/usr/local/mysql/bin:$PATH" # Apply changes source ~/.bash_profile # or source ~/.zshrc
Alternative Installation Methods
If MySQL isn't installed, consider these installation options:
| Operating System | Installation Method | Command |
|---|---|---|
| Linux (Ubuntu/Debian) | APT Package Manager | sudo apt update && sudo apt install mysql-server |
| Linux (CentOS/RHEL) | YUM Package Manager | sudo yum install mysql-server |
| macOS | Homebrew | brew install mysql |
| Windows | MySQL Installer | Download from mysql.com |
Verification
After adding MySQL to PATH, verify the fix by opening a new terminal/command prompt and running:
mysql --version mysql -u root -p
If successful, you should see MySQL version information and be able to connect to the MySQL server.
Conclusion
The MySQL "Command Not Found" error is typically resolved by ensuring MySQL is properly installed and its bin directory is added to the system PATH variable. Once configured correctly, MySQL commands will work from any directory in your terminal or command prompt.
