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

Ruby ActiveRecord Basics Migrations and Relationships Migrations

Andrew Carr
Andrew Carr
10,979 Points

Says: 'mysql' command not found

Hey! I've complete the Database Foundations block but so I'm 90% sure mysql should be recognized as a valid command, and I've also made sure it's running, but for some reason I can't perform the 'mysql -uroot' command. Any advice? Thanks.

Andrew Carr
Andrew Carr
10,979 Points

Other posts have suggested using homebrew. But I'm hesitant to use it since I don't know why I should, per se, when I've already downloaded mysql (specifically mysql workbench and mysql 5.6). Am I missing anything here? Thanks, again!

K Jo
K Jo
7,283 Points

I had this same issue. After trying a number of things to no avail, I found this link: http://apple.stackexchange.com/questions/98999/mysql-not-working-on-mountain-lion

then ran the suggested command:

sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'

It will then prompt you for your password. After your enter that, press cmd+t to open a new terminal tab, then type mysql -uroot.

I'm relatively new to this, so I don't really know why the above command worked, but i'm just happy it does for me since the issue was starting to get annoying. If anyone is able to break this command down and illustrate what it is doing, it would be helpful.

3 Answers

Homebrew is a good thing to install because it takes care of all of your updates on A LOT of things you might or might not install. Every day, something you've got running in your back ground may be updated or deleted and running a quick 'brew update' on your command line takes care of that (and you don't have to run it every day - but just saying - it does update things almost every day). New things that show up will be easier to install (usually) through homebrew.

Also - try mysql -u root -p (include the -p so it asks for the password, and keep the space, and make sure you mapped the mysql 'path' properly as well

Andrew Carr
Andrew Carr
10,979 Points

How do I ensure the mysql path is mapped properly?

Andrew

I apologize, but that I can't tell you. I just remember from installing (years ago because I use it so much) on my computer that you had to write some code so that the mysql command mapped to the proper location of the mysql app.

Andrew - not sure if you're still looking - but you have to map the mysql folder to your $PATH variable. This requires you to know how to add to your $PATH variable and to know where you SQL executable is stored.

If you don't want to take the whole console course - this video should do the trick

https://teamtreehouse.com/library/console-foundations/environment-and-redirection/environment-variables

Andrew Carr
Andrew Carr
10,979 Points

Hey! So I was thinking it'd involve that. That being said, I don't want to accidentally reassign something I'll significantly regret. That being said, I'm tempted to put in this command:

ls -s "/usr/local/mysql/bin/mysql" ~/bin/mysql

That being said, I have no guarantee that I've made the right association. Would you agree that is the right input?

Thanks!

Andrew - I don't know those commands - like I said - learning the console course - priarmily a mac guy never been a huge console user just followed the directions

Here's what I'd do

  1. which mysql will tell you path to the mysql exe file
  2. Find your config file
  3. In config file add text to change your $PATH variable (or bashrc file) For instance I have this line in my bashrc file for herokus export PATH="/usr/local/heroku/bin:$PATH" Just substitute the path to your mySQL where my heroku path is.

Do not forget :$PATH so as to append this to your already existing path.