user12056706
user12056706

Reputation:

mysql command is not found in macOS

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?

Upvotes: 10

Views: 21158

Answers (4)

Pawan Deore
Pawan Deore

Reputation: 182

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 

Upvotes: 0

Aravinda Reddy
Aravinda Reddy

Reputation: 31

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

Upvotes: 3

Arun Selin
Arun Selin

Reputation: 633

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

Upvotes: 14

Sahil Tah
Sahil Tah

Reputation: 298

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

Upvotes: 7

Related Questions