zsh

How to Fix – zsh command not found mysql Error on Mac

Encountering the “zsh command not found: mysql” error in the Zsh shell can hinder your ability to execute MySQL-related commands and tasks. This error occurs when the Zsh shell is unable to locate and recognize the “mysql” command.

In this guide, we will provide you with simple steps to resolve this error and regain control over your MySQL commands. By following the instructions outlined below, you will be able to fix the “zsh command not found: mysql” error and continue working with MySQL seamlessly in the Zsh shell.

Common Causes of the “zsh command not found: mysql” Error

There are two most common reasons for this error to occur in Zsh.

1: Missing MySQL Installation

The error can occur if MySQL is not installed on your system.

2: Incorrect PATH Configuration

If the directory containing the MySQL executable is not included in the PATH environment variable, Zsh won’t be able to find and execute the mysql command.

How to Fix – zsh command not found: mysql?

Follow these steps to fix the error and successfully use MySQL in the Zsh shell on a Mac:

Step 1: Verify MySQL Installation

Check if MySQL is installed on your system by running the following command in your terminal:

mysql --version

 

Step 2: Install MySQL

If MySQL is not installed on macOS, you can install it using Homebrew on Zsh with the following command:

brew install mysql

 

After the installation, you can use the mysql command again to check whether the error is fixed. In most cases, the problem will be solved after the installation of MySQL, however, if the problem still exists, you can perform some additional steps given below.

Note: If Homebrew isn’t installed on macOS, you can follow the guide here.

Step 3: Update the PATH Environment Variable

To ensure Zsh can find the mysql command, you need to add the MySQL executable directory to the PATH environment variable. Open the zshrc configuration file using a text editor preferably nano:

sudo nano /etc/zshrc

 

Add the following line at the end of the file, replacing “/usr/local/bin/mysql” with the actual path to the MySQL executable directory:

export PATH="$PATH:/usr/local/bin/mysql"

 

Save the changes using CTRL+X, Y to accept the changes and enter to exit the text editor.

Note: You can find mysql location from the following command:

which mysql

 

Step 4: Reload the Configuration File

To apply the changes made to the zshrc file, reload it by running the following command in the terminal:

source /etc/zshrc

 

Step 5: Test MySQL

Verify if the “zsh command not found: mysql” error is resolved by running the mysql command again:

mysql --version

 

If the command executes without errors and displays the MySQL version information, the error has been fixed.

Conclusion

The “zsh command not found: mysql” error can be resolved by ensuring MySQL is installed. Using Homebrew, you can easily install MySQL on macOS and fix the error. If still the error exists, updating the PATH environment variable in the zshrc configuration file, and reloading the configuration are additional steps you have to do to fix the error. By following the steps in the above guide, you can successfully fix the error and use MySQL seamlessly within the Zsh shell.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.