Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Mysql Command not found?

Hey everybody I've searched the forum and google yet I am still stumped and need some help. From my research I see that many people have this issue. I have tried uninstalling and re-installing mysql with no success. Yes it is running on my mac I even started mamp to see if that would make a difference.

I am trying to do the migrations course but when I reach the part where I type "mysql -uroot" into the terminal I am consistenly told " command not found".

I really need help with this as mysql/ rails is definitely important to my career path Thanks in advance for your help.

8 Answers

Ben Altieri
Ben Altieri
4,645 Points

Hi Peaches, you will need to put in the full path to the command for now. I will provide instructions on how to permanently update your path environment variable.

For now, just enter the following command:

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

  • Ben
Ben Altieri
Ben Altieri
4,645 Points

Have you tried to put in the full path to the mysql executable? Execute the following command: ps -ef | grep mysql Provide the output. Im downloading the x86_64 DMG installer for version 5.6 of MySQL. I will install it and show you how I find the mysql command.

Ben Altieri
Ben Altieri
4,645 Points

Ok, here is the link from which I just downloaded the Mac OS X version of MySQL version 5.6: http://dev.mysql.com/downloads/mysql/

Scroll down the page and select the download button second from the top for: Mac OS X 10.8 (x86, 64-bit), DMG Archive

Download and install it by double clicking the .pkg file. Then open up a terminal window on your Mac (its in the utilities folder underneath Applications). Run these commands:

cd /usr/local/mysql


cd . ; ./bin/mysqld_safe &

ps -ef | grep mysql

(you should see output like this below):

MACOSX-G0398:mysql root# ps -ef | grep mysql 0 72409 72342 0 10:58PM ttys004 0:00.03 /bin/sh ./bin/mysqld_safe 74 72484 72409 0 10:58PM ttys004 0:00.48 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/MACOSX-G0398.local.err --pid-file=/usr/local/mysql/data/MACOSX-G0398.local.pid 0 72489 72342 0 10:58PM ttys004 0:00.00 grep mysql

Now run these commands:


(As its name suggests, this will harden your mysql installation, if you are just learning mysql, you can skip this step, but if you are installing it to hand over to other teams in a professional environment, you should run this command and get used to living with it this way. It will first ask you for your root password to mysql which will be blank after an initial installation, so just hit enter, then it will ask you to choose a new mysql root password and then confirm it. Then select y for yes for the remaining questions).

Now for the answer to your question. If you didn't run the mysql_secure_installation script above, then just run the following command:

/usr/local/mysql/bin/mysql -uroot

However, if you did run the mysql_secure_installation, then you will need to pass the -p switch to the end of the above command so that it will ask you for the mysql root password as such:

/usr/local/mysql/bin/mysql -uroot -p

Below, I have copied and pasted my output from running the above command and it shows me at the mysql command prompt:

MACOSX-G0398:mysql root# /usr/local/mysql/bin/mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.6.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


Thank you Ben I have to dash out right now but I will definitely do this when I get back and tell you if it worked. :)

Hi Ben I did follow your steps and I did eventually get the latter part the statement that you have above. Even though that worked I still cannot run the command mysql -uroot. I am at a loss at this point.

Thanks Ben I actually found that direct path yesterday and it seems to have worked but now that that is fixed ruby is giving me problems. Which it was not doing in the past two weeks so out of the pan and into the fire. Thank you for your help :) gonna tackle this new and annoying challenge . Things that should take an hour or two ends up taking days with these issues.

Erik Gomez
Erik Gomez
6,170 Points

how would the path look if we have git installed?

John Simoneau
John Simoneau
Courses Plus Student 8,105 Points

I had the same problem and couldn't get that command to work so I reinstalled MySQL via the console. I have home-brew installed so my command was brew install mysql. If you don't have home-brew installed then I'd imagine the instructions are very similar. Right after doing that the mysql -uroot began working for me. Hope this helps for someone else sometime :)