10

I have installed MySQL with .dmg installation file according to the official page. But it returns command not found: mysql when I execute mysql command.

How to fix this issue?

1

4 Answers 4

14

The documentation for MySQL says:

When installing using the package installer, the files are installed into a directory within /usr/local matching the name of the installation version and platform. For example, the installer file mysql-5.7.29-osx10.13-x86_64.dmg installs MySQL into /usr/local/mysql-5.7.29-osx10.13-x86_64/.

Once you verify that there is a bin folder in this directory, you have to make sure that the terminal looks for the MySQL command there. This can be done by executing the following command:

export PATH=$PATH:/usr/local/<my-path>/bin

Sign up to request clarification or add additional context in comments.

3 Comments

why do you have double slash?
That is a typo. It should be a single slash.
hello, i found my path to my mysql, it's "/usr/local/mysql-8.0.27-macos11-arm64/bin", i am in my zshrc too, but i don't know how to put "export PATH=$PATH:/usr/local/<my-path>/bin" in to zshrc. How do i specify this path is for mysql? and where to put?
8

Adding the following line to .bash_profile worked for me:

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

Then either restart the terminal or to apply the changes to an existing session, run:

source ~/.bash_profile

Comments

3

If you had installed [email protected] using brew:

paste/type below command in terminal:

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

then paste/type:

mysql -u root

boom!!!!

reason: brew files are installed in usr/local/opt

Comments

0

Try this if you have not upgraded your OS and wants to access mysql

instead of    ->   mysql -u root -p
use           ->   /usr/local/mysql/bin/mysql -u root -p 

2 Comments

I think the idea is to use mysql instead of the full path for easy of use
For those who want to use mysql, edit your shell profile, if you're using Bash, this file is usually either ~/.bash_profile, ~/.bashrc, or ~/.profile. If you're using Zsh, it's likely ~/.zshrc. Add this line: export PATH="/usr/local/mysql/bin:$PATH", restart the terminal and try mysql -u root -p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.