zsh: command not found: mysql

When you try to run the mysql command in the terminal but the MySQL client is not correctly installed or configured on your system, you frequently get the error message “zsh: command not found: mysql.”

You must set up the MySQL client on your computer in order to address this problem. The following command can be used to instal MySQL on a Mac using the Homebrew package manager:

We need to add mysql location reference to zshrc file. Open the .zshrc file by running the following command:

nano ~/.zshrc

Do the following steps in that file:

  1. Paste the export PATH=”/usr/local/mysql/bin:$PATH” line in that end of that file.
  2. Hit CTRL + O
  3. Hit CTRL + Enter Key
  4. Hit CTRL + X

Above, /usr/local/mysql is the base directory location of your MySQL installation. You can find the base directory with the help of the following resource:

Close the terminal and restart it to test mysql command now. The mysql command should work in the terminal once the MySQL client has been installed and set up. By using the following command, you may test your installation by attempting to connect to the MySQL server:

Run the mysql command:

mysql

You can try with password also:

mysql -u root -p

Once you enter the right password, you will be able to connect to the MySQL server when this programme prompts you for the root password.

Please verify that the mysql command is not installed in a directory that is listed in the PATH environment variable if you continue to receive the same issue.
Run the command to check the installation location.

which mysql

It should give you the output like this:

/usr/local/mysql/bin/mysql