How to fix "command not found: mysql" in Zsh

Viewed 103729

I want to use MySQL with my Rails application.

After successfully installing the package and seeing the option to start and stop the server from the Preference Pane, if I execute

mysql --version

I get an error from zsh:

zsh: command not found: mysql

I understand that this has something to do with my $PATH variable and if I display my $PATH I get:

/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/aniruddhabarapatre1/.rvm/gems/ruby-2.2.1/bin:/Users/aniruddhabarapatre1/.rvm/gems/ruby-2.2.1@global/bin:/Users/aniruddhabarapatre1/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/Users/aniruddhabarapatre1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/opt/ImageMagick/bin:/usr/local/MacGPG2/bin:/Users/aniruddhabarapatre1/.rvm/bin

How do I resolve this error to get Mysql up and running?

7 Answers

You paste this line to append the path to MySQL to your environment variables:

export PATH=${PATH}:/usr/local/mysql/bin/

Then reload your environment variables with one of the following commands:

source ~/.zshrc   # If you use Oh-My-Zsh
source ~/.bashrc  # If you use Default Bash

On the latest MacOS, Catalina, I used this open the zsh config and edit:

vi ~/.zshrc  

and added

export PATH=${PATH}:/usr/local/mysql/bin/

then ran

source ~/.zshrc                            

to make it work

Reopen a teminal and run mysql -u root -p, input the password and you can log into your MySQL account.

On MacOs Catalina, open a terminal and run:

 sudo nano /etc/paths

And add to end of file:

/usr/local/mysql/bin

Save the changes and quit, then reload the terminal.

Open a new terminal and run:

 mysql -u root -p

For my MacOS Catalina system I tried everything above, but it didn't work. Input the code in your terminal:

/usr/local/mysql/bin/mysql -uroot -p

Thanks go to the "How to Install MySQL on MacOS Big Sur" video.

It worked also for MacOS Big Sur with an ARM processor.

In my case those steps helped:

  1. export PATH=$PATH:/usr/local/Cellar/mysql/8.0.25_1/bin
  2. mysql -u root -p

In the terminal run:

export PATH=/usr/local/Cellar/mysql/8.0.26/bin:$PATH

Then, if you run:

mysql

It should return:

Access denied for user 'user'@'localhost' (using password: NO)

Run:

mysql -u root -p

It should ask for your password and then be good to go.

Related