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

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Help - rake db:create fails. Tried installing MySQL via command line, I get an error still.

Hi, so I've run into an issue that is preventing me from progressing throughout this course. I've tried looking at related questions and even this one here: https://teamtreehouse.com/forum/activerecord-basics-dbcreate-not-working-with-biller-d-mysql

So after creating the app in the video, I type rake db:create. However the first time I did this (I still have mySQL installed from their website for the previous Treehouse lesson) the process fails. Here's what I get:

alborzs-mbp:biller alborz$ rake db:create
rake aborted!
LoadError: dlopen(/Users/alborz/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-13/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/alborz/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-13/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
  Reason: image not found - /Users/alborz/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-13/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/mysql2-0.3.17/lib/mysql2.rb:8:in `require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/mysql2-0.3.17/lib/mysql2.rb:8:in `<top (required)>'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `each'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `each'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler.rb:133:in `require'
/Users/alborz/biller/config/application.rb:7:in `<top (required)>'
/Users/alborz/biller/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

Then, I tried typing mysql in the command line prompt to see what I get:

alborzs-mbp:biller alborz$ mysql
-bash: mysql: command not found

So I thought that it was strange that the command was not found, so I decided to install MySQL via the command line after checking out https://teamtreehouse.com/forum/activerecord-basics-dbcreate-not-working-with-biller-d-mysql

I have OS X, and when I was installing it despite already having it downloaded from their website for the Treehouse tutorial before, I had noticed a message in the install messages in the command line that it could cause a lot of trouble:

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

So now I'm nervous. After typing mysql in again this is what I get this time around:

alborzs-mbp:biller alborz$ mysql
dyld: Library not loaded: @@HOMEBREW_PREFIX@@/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/bin/mysql
  Reason: image not found
Trace/BPT trap: 5

When I try to start the server this is what I get:

alborzs-mbp:biller alborz$ mysql.server start
/usr/local/bin/mysql.server: line 256: my_print_defaults: command not found
/usr/local/bin/mysql.server: line 276: cd: @@HOMEBREW_CELLAR@@/mysql/5.6.22: No such file or directory
Starting MySQL
 ERROR! Couldn't find MySQL server (@@HOMEBREW_CELLAR@@/mysql/5.6.22/bin/mysqld_safe)

Finally, when I tried to do rake db:create following the installation via the command line, this is what I got:

alborzs-mbp:biller alborz$ rake db:create
rake aborted!
LoadError: dlopen(/Users/alborz/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-13/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle, 9): Library not loaded: @@HOMEBREW_PREFIX@@/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/lib/libmysqlclient.18.dylib
  Reason: image not found - /Users/alborz/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-13/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.bundle
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/mysql2-0.3.17/lib/mysql2.rb:8:in `require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/mysql2-0.3.17/lib/mysql2.rb:8:in `<top (required)>'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `each'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `each'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'
/Users/alborz/.rvm/gems/ruby-2.1.1/gems/bundler-1.7.4/lib/bundler.rb:133:in `require'
/Users/alborz/Desktop/biller/config/application.rb:7:in `<top (required)>'
/Users/alborz/Desktop/biller/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

I also tried https://teamtreehouse.com/forum/rake-dbcreate-error but I still get the same error when trying to run the rake db:create command.

So now I can't progress through this course. :(

Any help is appreciated!

As a temporary workaround, you could try using SQLite rather than MySQL.

In the long term you will need to get MySQL running. My general advice would be to uninstall all versions of MySQL and try a fresh install - but I'm not familiar enough with OSX to say anything beyond that.

I'm using Rails 4.1.8 and this is the command I would need to use:

rails new -d sqlite3 biller

Rails should actually default to using sqlite, so the following would work for me as well:

rails new biller

But it is good practice to be specific.

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Jesse Fisher So it looks as if this does enable the rake db:create command to run; however, going through the course, the commands are different, and some I don't know if I can do as in the video.

For example:

sqlite> .databases
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main                                                                       
sqlite> use biller_development
Error: near "use": syntax error
sqlite> 
sqlite> .tables
sqlite> 

So I can't even change the database like in the video at 10:38.

I'm using Rails 4.1.7.

6 Answers

Ross Litzenberger
Ross Litzenberger
11,706 Points

I could not replicate the error from mysql . sorry. I change the rails application to support mysql if you want to use it feel free to merge into your project.

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Thanks Ross. I think the problem may be because I had downloaded osx-gcc-installer from one of the the other Ruby tutorial videos which overwrote some files in dev tools.

I think that I may need to reinstall my OS. I ran into a former issue also caused by osx-gcc-installer where I couldn't install gems which you can see here. Thankfully the awesome teachers here were able to help: https://teamtreehouse.com/forum/following-the-installation-of-osxgccinstaller-i-cannot-install-gems-basically-use-ruby-in-programming

I did some research and came across these that show the similar error messages as shown when I type in mysql and other stuff here we've already gone over:

https://github.com/Homebrew/homebrew/issues/26544 https://github.com/Homebrew/homebrew/issues/26367

Unfortunately as far as I can see it appears that osx-gcc-installer's issues will continue unless that issue can be addressed. :(

Ivan Polchenko
Ivan Polchenko
10,852 Points

I thought that you have to manually create the mysql db, and then just follow it up with rake db:migrate ?

last time i had anything relevant to do was a while ago. But my naive assumption was that the rake db:create only works in Mongo??

Every single time I've been doing stuff I just create DB manually externally.. and then come back and do rake db:migrate

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Hi Ivan, I've tried using sqlite3, but some of the commands are different when going through the video since I'm not using MySQL. When going through the ActiveRecords Basics video on Migrations, I can't do what the teacher is doing in some instances, for example changing the database via the terminal (see 10:38 in the ActiveRecord Basics - Migrations video).

It was strange before because I had downloaded MySQL manually from their website but when I ran mysql in the terminal the terminal said no such command was found.

Ross Litzenberger
Ross Litzenberger
11,706 Points

Alborz are you still have problem with mysql?

Ross Litzenberger
Ross Litzenberger
11,706 Points

I see you using homebrew. That i use on my mac. open terminal and type in "which mysql". Tell me what it output. 2nd question could you post the app on github i will pull it down.