Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to fix the "mysql: command not found" error

This guide helps you when your server says it cannot find the mysql command.

Databases2 min read7 steps

This guide needs root access, so it fits VPS and dedicated server customers.

What does the error mean?

You use SSH to type commands on a server. SSH is a safe way to control a remote computer. When you type mysql and see "command not found", one of two things is true.

  • MySQL is not installed.
  • MySQL is installed, but the system does not know where it is. The system looks for programs in folders listed in a setting called PATH. Think of PATH as a list of places to search.

Step 1: Check if it is installed

  1. Log in to your server with SSH.
  2. Type:
    which mysql
    This shows where the mysql program is. Nothing printed means it was not found.
  3. Try a search:
    find / -name mysql -type f 2>/dev/null
    This searches the whole server for a file called mysql. It may take a moment.

Step 2a: It exists but is not in PATH

Say the search found /usr/local/mysql/bin/mysql. You can add its folder to PATH.

  1. Run:
    export PATH=$PATH:/usr/local/mysql/bin
    This adds the folder for your current session only.
  2. To keep it, add that same line to the end of the file ~/.bashrc.
  3. Run source ~/.bashrc to load it.
  4. Type mysql --version to test.

Step 2b: It is not installed

Install the MySQL client. The command depends on your system.

On Ubuntu or Debian:

sudo apt update
sudo apt install mysql-client

On CentOS, AlmaLinux or Rocky Linux:

sudo yum install mysql

Your server may use MariaDB, a close cousin of MySQL. In that case, install mariadb or mariadb-server instead. Its command is still called mysql.

Warning: Do not install a server package over an existing database server without a backup. You could break your sites.

Tip: Install only the client if you just need the command. The server package is for running databases.

Check it worked

Type mysql --version. If a version number appears, it works.

Still stuck? Open a support ticket.

Quick recap

  • The error means MySQL is missing or not in PATH.
  • Use which mysql to check.
  • Add the folder to PATH, or install the client.
  • Test with mysql --version.