How to Fix “MySQL Command Not Found” Error

June 14, 2024 / MySQL

This guide illustrates how to fix the “MySQL Command Not Found” error. MySQL is an open-source database management system (DBMS) that is well-matched with Linux, Windows, and MacOS. Sometimes you may get a “Command Not Found” error irrespective of the operating system you are using.

First, let us try to understand this error-

If you encounter the error message “mysql: command not found” when attempting to run the mysql command, it means that the mysql command is not available in your system’s path. This issue can occur if the mysql command is not installed on your server or if it is installed but the directory, containing the mysql binary is not included in the system’s path.

You may fix this issue by following subsequent steps-

Check if MySQL is installed on Your System –

  1. Enter the below command –
    which mysql
  2. If MySQL is previously installed, the above command will print the path to the mysql binary.
  3. However, if the command does not print anything, it means that MySQL is not installed on your system, and that is the reason you are receiving an error “mysql command not found”.

Install MySQL, If It’s Not Installed –

If MySQL is not installed, you may require installing it to resolve the “mysql command not found” error. The installation process varies depending on the operating system.
Here, we provide instructions for Ubuntu and Red Hat –

To install MySQL on Ubuntu, you can use the apt package manager, which is included by default on Ubuntu for installing, updating, and managing software packages.

Follow these steps-

  1. Update the package index –
    Run the following command –
    sudo apt update
    The above command may take some time to complete, depending on the number of packages that need updating.
  2. Install MySQL –
    After updating the package index, install MySQL using the apt command-
    sudo apt install mysql-server
    This will also start the MySQL service and configure it to start automatically at boot.
  3. Set the root password-
    After starting the MySQL service, you need to set a password for the MySQL root user-
    sudo mysql_secure_installation
    This command starts the MySQL root password setup wizard, which will guide you through setting a password for the root user.
  4. Log in to MySQL-
    After setting the root password, you can log in to the MySQL server using the mysql command-
    mysql -u root –p

You will be prompted to enter the root user password that you set in the previous step.

In this guide, we discussed the “mysql command not found” error and provided instructions to fix it by installing MySQL on different operating systems. Hope you found this article easy to understand. If you still encounter any difficulties, please reach out to our support team for assistance.

Dominos Search