How to fix "command not found: mysql" in Zsh
Asked Answered
A

8

56

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?

Attestation answered 8/3, 2016 at 2:53 Comment(0)
A
27

This was a problem within my configuration and $PATH variable. I followed the "How to install MySQL on Mac OS X El Capitan" tutorial to resolve this.

In my terminal, I opened up the configuration by running vi ~/.zshrc, then located the line to export my PATH

export PATH="..."

and appended

:/usr/local/mysql/bin

to it which resolved my issue.

Attestation answered 9/3, 2016 at 1:23 Comment(1)
do not forget to relaunch terminal :)Celt
B
102

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
Beberg answered 16/4, 2019 at 18:52 Comment(1)
I ran "source ~/.zshrc" on my VS code integrated terminal trying to fix my problem, which was the same as the question that was asked, and not just it didn't fix, but now my VS Code terminal won't stay open. When I open it or click open new terminal, it opens for a second but then it closes. Do you know what might be the cause?Dolmen
M
79

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.

Marlow answered 16/10, 2019 at 2:24 Comment(1)
This approached worked for Macbook Pro M2. Thank you.Plash
O
46

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
Outlook answered 4/4, 2020 at 5:51 Comment(1)
didn't work for meKeeter
T
29

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.

Trophozoite answered 12/6, 2020 at 13:20 Comment(1)
Excellent answer! If everybody agrees the issue is on the path, no need to make a lot of changes, just use the correct path :)Rasp
A
27

This was a problem within my configuration and $PATH variable. I followed the "How to install MySQL on Mac OS X El Capitan" tutorial to resolve this.

In my terminal, I opened up the configuration by running vi ~/.zshrc, then located the line to export my PATH

export PATH="..."

and appended

:/usr/local/mysql/bin

to it which resolved my issue.

Attestation answered 9/3, 2016 at 1:23 Comment(1)
do not forget to relaunch terminal :)Celt
B
8

In my case those steps helped:

  1. export PATH=$PATH:/usr/local/Cellar/mysql/8.0.25_1/bin
  2. mysql -u root -p
Bettencourt answered 16/6, 2021 at 4:27 Comment(0)
F
2

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.

Fernandes answered 9/2, 2022 at 11:16 Comment(0)
G
0

This looks right, although it doesn't work right

export VOLTA_HOME="$HOME/.volta" export PATH="$VOLTA_HOME/bin:$PATH" export PATH=/usr/local/Cellar/mysql/8.0.33/bin:$PATH

I have to manually run export PATH=${PATH}:/usr/local/mysql/bin/ to get mysql to work..

What am I missing here?

Gaiser answered 7/12, 2023 at 23:46 Comment(1)
Are you adding the line to your .zshrc?Micturition

© 2022 - 2024 — McMap. All rights reserved.