Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  Database  >  How to Fix “MySQL Command Not Found” Error?
Top Scroll

How to Fix “MySQL Command Not Found” Error?

 3 min

MySQL is an open-source database management system (DBMS) that’s compatible with Linux, Windows and MacOS. You may get a “Command Not Found” error regardless of the operating system you are using.

In this article, we will understand how to fix the error message “MySQL command not found.”

What is MySQL Command Not Found Error?

If you’re getting the error message, “mysql:commandnotfound” when trying to run the mysql command, meaning that the mysql command is not present in your system’s path.

This can even happen if the mysql command is not installed on your server, or if the mysql command is already installed but the directory that contains the mysql binary is not included in the system’s path.

Related: MySQL Database (cPanel)

You can fix the error by following the below steps:

Step 1: Check if MySQL is Installed on Your System

The first step is, checking if MySQL is installed on your system. To do so, type the command given below:

which mysql

If MySQL is already installed, this command will print the path to the mysql binary.

If the command does not print anything, it means that MySQL is not installed on your system, and that’s why you are getting the “mysql command not found” error.

If the command does not print anything, it means that MySQL is not installed on your system, and that’s why you are getting the “mysql command not found” error.

Step 2: Install MySQL, If It’s Not Installed

If MySQL is not installed, then you need to install it to fix the “mysql command not found” error. 

The process to install MySQL is complex, and depends on the OS, here we’ve mentioned the details for Ubuntu and Redhat.

Installing MySQL on Ubuntu

For installing MySQL on Ubuntu, you can use the apt package manager.

The apt package manager is included by default on Ubuntu and is used for installing, updating and managing the software packages on the system.

To install MySQL using apt, follow the steps given below:

Update the package index: To do so, run the command:

sudo apt update

This command takes time to complete, depending on the number of packages that need to be updated.

2: Install MySQL: After updating the package index, you can install MySQL using the apt command. To run this, type the command:

sudo apt install mysql-server

This will also start with the MySQL service and enable it to start automatically whenever the system is booted. In the next step, set the root password for MySQL. After starting the MySQL service, you will need to set a password for the MySQL root user.

To set the root password for MySQL, run the command:

sudo mysql_secure_installation

This will begin the MySQL root password setup wizard, that guides you through the process of setting a password for the root user.

In the next step, Login to MySQL: After setting the root password, you can login into the MySQL server using the mysql command.

To login, run the command:

mysql -u root -p

This will ask you for the password for the root user. Enter the password you set in the previous step to login to the MySQL server.

Conclusion

In this article, we have discussed what is “mysql command not found” error and the several ways through which we can fix this error in different operating systems.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.