Encountering the ‘MySQL command not found’ error usually indicates that MySQL software is not installed on your system or its installation path is not included in the system’s PATH environment variable.

This guide outlines steps to resolve the issue-

  1. Understanding the Error-
    When trying to execute MySQL from the command line and encountering the ‘MySQL command not found’ error, it means the system’s helpless to locate the MySQL executable within directories listed in the PATH environment variable. This error commonly arises in new installations or when switching between multiple MySQL versions.
  2. Verifying MySQL Installation-
    1. Begin by confirming whether MySQL installed. Execute the following command in your terminal-
      mysql –version
    2. If MySQL is installed, this command returns its version. If not, MySQL needs to be installed.
  3. Installing MySQL-
    1. For Linux:
      sudo apt-get update
      
      sudo apt-get install mysql-server
    2. For macOS:
      brew install mysql
    3. For Windows:
      Download the installer from the MySQL website and follow the installation wizard.
  4. Updating the PATH Environment Variable-
    If MySQL installed but unrecognized, append its directory to the PATH environment variable.

    1. For Linux and macOS:
      1. Locate the MySQL installation path:
        which mysql
      2. Add the path to your profile script (like .bashrc or .zshrc):
        echo 'export PATH="/path/to/mysql/bin:$PATH"' >> ~/.bashrc
        
        source ~/.bashrc
      3. Replace “/path/to/mysql/bin” with the actual path.
    2. For Windows-
      1. Search for ‘Environment Variables’ in the Start menu.
      2. Edit the ‘Path’ variable under ‘System variables.’
      3. Add the path to the MySQL bin directory.
  5. Verifying the Fix-
    After installation or PATH update, re-run “mysql –version”. If the setup is correct, the command should now display the MySQL version.
  6. Troubleshooting- If the issue persists-
    1. Ensure correct permissions to access MySQL.
    2. Check for typos in the PATH variable.
    3. Restart your terminal or system to apply changes.

That is it!

You can more KB about How to Inspect the Sizes of MySQL Databases and Tables.

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

How to Assign a Domain to a Dedicated IP in WHM

How to Assign a Domain to a Dedicated IP in WHM

If you are a Webmaster, you should be thoroughly familiar with the WHM program. The…

How to Select the Most Suitable Softaculous Script

In this article, you’ll discover how to choose the best Softaculous script. It provides a…

How to Enable Extended Logging

To enable extended logging in Exim to trace nobody’s mails. Try the following trick. Edit…