11

I seem to be missing something as all of the tutorials that show how to run MySQL from OSX's command line aren't working.

I can turn the MySQL Server status on and off via System preferences, but if I follow one of the tutorial that shows how to run from the command line using sudo mysqld_safe it returns the sudo: mysqld: command not found

I've also tried logging into MySQL using mysql -u root -p and I get bash: mysql: command not found

/usr/local/mysql/bin/ does exist I just feel like something wasn't installed properly on the client side. Any help figuring out how to access mysql from the terminal would be very much appreciated. Thanks in advance.

3 Answers 3

26

/usr/local/mysql/bin is not in the default $PATH. $PATH is the list of directories that are searched when you try to use an executable without specifying a complete path.

You either need to use the full path (/usr/local/mysql/bin/mysql_executable_here) or add it to your $PATH:

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

For macOS Mojave and earlier

You can add this line to a file called .profile in your home directory to execute it each time you create a new shell:

echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.profile
source ~/.profile
mysql -u USERNAME -p

For macOS Catalina and later

Starting with macOS Catalina, Mac devices use zsh as the default login shell and interactive shell and you have to update .zprofile file in your home directory.

echo 'export PATH="$PATH:/usr/local/mysql/bin"' >> ~/.zprofile
source ~/.zprofile
mysql -u USERNAME -p
Sign up to request clarification or add additional context in comments.

14 Comments

i used `sudo ./bin/mysqld_safe and that turned it on the server. I still can;'t figure out how to log into the client though.
i got it. I had to use sudo ./bin/local/mysql -u root -p Is there an easier way to do this, or do I have to always put the directory in the sudo line?
Have you read my answer? :/ I feel that it should answer this exact question and I'm not sure how to phrase it if it's not enough.
sorry. I got ahead of myself. Using the export line worked, but won't this screw up anything other than running mysql commands? Do I have to undo this when I'm finished?
Yes @StuartKuredjian, create it if it doesn't exist. This is what the suggested command will do anyways.
|
6

I had this kind of problem as well. I resolved the issues like:-

  1. go to the directory cd /usr/local/mysql/bin/
  2. put this command ./mysql -u root -p;
  3. it will ask you password the root password you get at the time of installation. that way you will get your mysql connected to the database... hope that helps..

Comments

0

unless I'm missing something here, I believe you can just install mump and also run MySQL workbench. and you won't have to deal with a lot of these issues.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.