can't access mysql from command line mac

MysqlTerminal

Mysql Problem Overview


mysql on os x 10.6 is located in /usr/local/mysql/bin/mysql

I get command not found when I type mysql --version in the terminal. Is this because the socket path is wrong? if so how do I fix it?

thanks

Mysql Solutions


Solution 1 - Mysql

Just do the following in your terminal:

echo $PATH

If your given path is not in that string, you have to add it like this: export PATH=$PATH:/usr/local/ or export PATH=$PATH:/usr/local/mysql/bin

Solution 2 - Mysql

I'm using OS X 10.10, open the shell, type

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

it works temporary.if you use Command+T to open a new tab ,mysql command will not work anymore.

We need to create a .bash_profile file to make it work each time you open a new tab.

nano ~/.bash_profile

add the following line to the file.

# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/mysql/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

Save the file, then open a new shell tab, it works like a charm..

by the way, why not try https://github.com/dbcli/mycli

pip install -U mycli

it's a tool way better than the mysqlcli.. A command line client for MySQL that can do auto-completion and syntax highlighting

Solution 3 - Mysql

On OSX 10.11, you can sudo nano /etc/paths and add the path(s) you want here, one per line. Way simpler than figuring which of ~/.bashrc, /etc/profile, '~/.bash_profile` etc... you should add to. Besides, why export and append $PATH to itself when you can just go and modify PATH directly...?

Solution 4 - Mysql

On mac, open the terminal and type:

cd /usr/local/mysql/bin

then type:

./mysql -u root -p

It will ask you for the mysql root password. Enter your password and use mysql database in the terminal.

Solution 5 - Mysql

I've tried all the solutions from the answers but couldn't get mysql command to work from the terminal, always getting the message

bash: command not found

The solution is to change the .bash_profile, and add the mysql path to .bash_profile

To do so follow these steps:

  1. Open a new Terminal window or make sure you are in the home directory

  2. Open .bash_profile using

    nano .bash_profile

  3. Add the following command to add the mysql path

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

  4. Press Ctrl+X, then press y and press enter.

The following is how my .bash_profile looks like enter image description here

Solution 6 - Mysql

adding this code to my .profile worked for me: :/usr/local/mysql/bin

Thanks.

P.S This .profile is located in your user/ path. Its a hidden file so you will have to get to it either by a command in Terminal or using an html editor.

Solution 7 - Mysql

I think this is the more simpler approach:

  1. Install mySQL-Shell package from mySQL site
  2. Run mysqlsh (should be added to your path by default after install)
  3. Connect to your database server like so: MySQL JS > \connect --mysql [username]@[endpoint/server]:3306
  4. Switch to SQL Mode by typing "\sql" in your prompt
  5. The console should print out the following to let you know you are good to go:

Switching to SQL mode... Commands end with ;

Go forth and do great things! :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael InsalacoView Question on Stackoverflow
Solution 1 - MysqlsaschaView Answer on Stackoverflow
Solution 2 - Mysqluser4985526View Answer on Stackoverflow
Solution 3 - MysqlTom AugerView Answer on Stackoverflow
Solution 4 - Mysqluser12974639View Answer on Stackoverflow
Solution 5 - MysqlAmit KumarView Answer on Stackoverflow
Solution 6 - Mysqljon jonView Answer on Stackoverflow
Solution 7 - Mysqllowlow20View Answer on Stackoverflow