Knowledge Base
MilesWeb / Database

How to Fix “MySQL Command Not Found” Error?

Approx. read time : 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.

Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Excellent
Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
Harshada
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
MR
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna