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

Can't follow instructions at 2:15 here (both rake db:create and mysql -uroot won't work)

Hey folks!

First off: for those who haven't taken this particular course, the instructor decides to roll with mysql instead of sqlite right at the beginning. In fact, when I ran rails new -d mysql biller as instructed, I noticed that I got Installing mysql2 0.3.17 in the resolving dependencies messages.

In the previous course, we used MySQL Workbench a bunch (utilizing localhost; I have a Macbook running OS X Yosemite, FYI); however, we haven't yet used MySQL within the context of Rails/Ruby. That means that "hey, we aren't using the default version of MySQL" is actually a non-trivial thing. Here's why!

This is what I get when I run rake db:create in the biller project folder:

rake aborted!
LoadError: dlopen(/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
  Reason: image not found - /Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
/Users/TCB/biller/config/application.rb:7:in `<top (required)>'
/Users/TCB/biller/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

I believe I was able to get --trace to work, and this was the result:

rake aborted!
LoadError: dlopen(/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
  Reason: image not found - /Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/mysql2-0.3.17/lib/mysql2.rb:8:in `require'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/mysql2-0.3.17/lib/mysql2.rb:8:in `<top (required)>'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `each'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `each'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler.rb:133:in `require'
/Users/TCB/biller/config/application.rb:7:in `<top (required)>'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/TCB/biller/Rakefile:4:in `<top (required)>'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:687:in `raw_load_rakefile'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Users/TCB/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/Users/TCB/.rbenv/versions/2.1.3/bin/rake:23:in `load'
/Users/TCB/.rbenv/versions/2.1.3/bin/rake:23:in `<main>'

Just to try and see what else might work/not work, I also tried the next step, which is to run mysql -uroot. This produces the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I know that this step of the class has a bunch of related forum questions already, but the picture they paint doesn't seem to fit my questions yet. I tried Googling my errors, too, but just didn't seem to find something that helped. Thanks so much in advance--right now I'm stuck, unable to move forward, and your help is so appreciated!

6 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

My first advice for all people using Macbooks would be to throw them away, sell them or use as a trays/tables for more manly hardware, but I guess this is always out of the question ;).

So second best thing would be to not use MySQL. I had problems with it myself, same course, I had to change my password (which I never set in the first place), I later helped someone who was in the same situation and it worked: https://teamtreehouse.com/forum/rake-dbcreate-mysql

But I see that you already tried that and it worked only temporarily. Hmmm...did you edit the config/database.yml file to reflect your current password that you just set?

I personally use SQLite3 for development and testing (it's easier, no setup) and PostgreSQL for production (since I only deploy on Heroku), so I haven't had any more contact (and problems) with MySQL since this course.

This is super helpful, thank you! I tried adding my password to the config file, and now I'm getting this!

biller_development already exists
biller_test already exists

I then used mysql -u root -p instead of mysql -uroot (based on other folks' experiences) aaaaaaand:

Welcome to the MySQL monitor.

WOOHOO!

:clap: :clap: :clap: :clap: :fireworks: :fireworks: :sparkler: :sparkler:

Thanks so much! And thanks for making me feel like, "hey, it's okay to just roll something else as long as you can still follow along."

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I'm glad this this helped you :). Good luck with your learning!

After reading this Stackoverflow answer, I was able to fix my issue by going to terminal and typing:

mysql.server start

...and was able to solve both my issues with mysql -uroot, as well as rake db create. Hope this also helps someone!

Well, I wasn't sure if those sudo commands were a good idea but I went for it. Now I'm getting new errors, which might mean progress? I did a combination of that link and also this:

resetting a lost mysql root pw

However, even though some of that felt like progress, and even though I thought I was now setting a root password, it doesn't seem to work. When it asks for my password and then I give it, I still get:

Access denied for user 'root'@'localhost' 
(using password: NO)Please provide the root password for your mysql 
installation

I'm also getting this:

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", 
"pool"=>5, "username"=>"root", "password"=>nil, 
"socket"=>"/tmp/mysql.sock", "database"=>"biller_test"}

At this point, I'm considering uninstalling MySQL Workbench and all of the related files, and then using the brew method to install it instead.

I'm also just having a hard time wrapping my brain around it all. For instance, not sure if I have to cd into the project directory to do all of the mysql stuff, or not.

Any advice?

ETA: Brandon Barrette I tried that, and also tried setting a new one. No good. Thanks for watching out for me though! :)

Brandon Barrette
Brandon Barrette
20,485 Points

On OSX your root password is the password For your user account of I remember correctly.

Brandon Barrette
Brandon Barrette
20,485 Points

I would use home brew to install MySQL, much easier.

Actually though...I don't think that MySQL is the issue. I switched to a second computer b/c I don't care if that one has a screwed up development environment, and tried a bunch of things. Here's what I almost thought had worked:

  • stopped trying to use rbenv and 2.1.5, and just ran with the ruby that I had installed a while ago (2.0.0p353)
  • uninstalled 2.1.5 using rbenv
  • used these instructions to completely start from scratch when it comes to mysql.
  • based on this post, I installed mysql2 after that by using gem install mysql2. When I was trying to use 2.1.5 that I installed with rbenv, it wasn't working.
  • created the project with rails new -d mysql biller as instructed in the course.

...and I'm back to getting that password error when I try to rake db:create.

Access denied for user 'root'@'localhost' (using password: NO) Please provide the root password for your mysql installation

I try the two possible passwords that I think it can be it should be and eventually receive another "couldn't create database:

Access denied for user 'root'@'localhost' (using password: NO)
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `connect'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `initialize'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/jwithington/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/jwithington/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:87:in `connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/mysql_database_tasks.rb:28:in `rescue in create'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/mysql_database_tasks.rb:15:in `create'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:88:in `create'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:102:in `block in create_current'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:225:in `block in each_current_configuration'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:224:in `each'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:224:in `each_current_configuration'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:101:in `create_current'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:240:in `call'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:240:in `block in execute'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:235:in `each'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:235:in `execute'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jwithington/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/task.rb:165:in `invoke'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:156:in `invoke_task'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:112:in `block (2 levels) in top_level'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:112:in `each'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:112:in `block in top_level'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:121:in `run_with_threads'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:106:in `top_level'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:84:in `block in run'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:182:in `standard_exception_handling'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/lib/rake/application.rb:79:in `run'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/bin/rake:23:in `load'
/Users/jwithington/.rvm/gems/ruby-2.0.0-p353/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/tmp/mysql.sock", "database"=>"biller_test"}

and I still get this if I try mysql -uroot:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Maybe Hampton Catlin himself can help out? I'm not getting why this database won't work, and I'm having a hard time finding anything online other than what I tried (above). Feeling a bit in over my head here. :grinning: In the morning, it might be back to trying to set a root password for mysql.

Brandon Barrette
Brandon Barrette
20,485 Points

Yeah I hear ya! I applaud your tenacity in trying to figure this out.

You can always use SQLite as a database for now until you can figure out why MySQL is not working. That requires a simple edit to the gemfile and you're good to go.

I myself use PostgreSQL after running into problems with MySQL and comparability issues with certain gems.

That's good to know! I really do sometimes feel like this kinda issue is the real learning that comes alongside the intended learning...but if it makes me stall out completely, maybe I should move along. :grinning:

And thanks for the compliment! It feels more like boneheaded "why won't this work?!?!" from over here, but tenacity? I like it!

Well this is odd.

Now, when I'm in the project folder, I tried running mysql -u root -p because of this thread. I got into mysql and the prompt worked, so, woo!

However, when I exit from the mysql prompt and go back to the project directory, I'm back to Access denied for user 'root'@'localhost' (using password: NO)Please provide the root password for your mysql installation.

Hmm....