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?

informatik01
  • 16,038
  • 10
  • 74
  • 104
  • This is similar to - https://stackoverflow.com/questions/26554818/using-mysql-in-the-command-line-in-osx-command-not-found or https://stackoverflow.com/questions/10577374/mysql-command-not-found-in-os-x-10-7) – Arun Selin Nov 25 '19 at 06:19

4 Answers4

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

informatik01
  • 16,038
  • 10
  • 74
  • 104
Arun Selin
  • 603
  • 4
  • 11
  • why do you have double slash? – maahd Mar 20 '20 at 14:40
  • That is a typo. It should be a single slash. – Arun Selin Mar 21 '20 at 15:15
  • 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//bin" in to zshrc. How do i specify this path is for mysql? and where to put? – EntzY Nov 09 '21 at 08:32
7

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
Sahil Tah
  • 300
  • 1
  • 3
  • 9
2

If you had installed mysql@5.7 using brew:

paste/type below command in terminal:

echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

then paste/type:

mysql -u root

boom!!!!

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

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 
Pawan Deore
  • 162
  • 3
  • 10