'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?



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[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

Solution 4:[4]

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 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 informatik01
Solution 2 Sahil Tah
Solution 3 Aravinda Reddy
Solution 4 Pawan Deore