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 - db:create not working with biller -d mysql!

UPDATE: Found a solution, see answers

UPDATE

I found this http://stackoverflow.com/questions/10557507/rails-mysql-on-osx-library-not-loaded-libmysqlclient-18-dylib

which sounded pretty similar to my problem so I ran the suggested fixes. Now I'm getting a new error message:

biller Tom$ rake db:create
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"biller_development"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"biller_test"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)

I'm pretty sure I'm using exactly the same versions of both ruby (2.1.1) and Rails (4.0.3) as the video - I have installed and activated via RVM.

I can create the application fine with:

rails new biller -d mysql

I then go into the application and double check my ruby and rails versions - all good!

When I try:

rake db:create

The rake aborts with the following error messages:

biller Tom$ rake db:create
rake aborted!
LoadError: dlopen(/Users/Tom/.rvm/gems/ruby-2.1.1@biller/extensions/x86_64-darwin-12/2.1.0-static/mysql2-0.3.16/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/Tom/.rvm/gems/ruby-2.1.1@biller/extensions/x86_64-darwin-12/2.1.0-static/mysql2-0.3.16/mysql2/mysql2.bundle
  Reason: image not found - /Users/Tom/.rvm/gems/ruby-2.1.1@biller/extensions/x86_64-darwin-12/2.1.0-static/mysql2-0.3.16/mysql2/mysql2.bundle
/Users/Tom/.rvm/gems/ruby-2.1.1@biller/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `require'
/Users/Tom/.rvm/gems/ruby-2.1.1@biller/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require'
/Users/Tom/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.1/lib/bundler.rb:132:in `require'
/Users/Tom/Documents/web design materials/treehouse/ruby/projects/biller/config/application.rb:7:in `<top (required)>'
/Users/Tom/Documents/web design materials/treehouse/ruby/projects/biller/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

I think the issue is only for mysql, because the first badge for ActiveRecord worked fine with sqllite3.

I've compared the gem files from my own application and also the instructors application - they are apparently identical but here it is again

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'

# Use mysql as the database for Active Record
gem 'mysql2'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

Can anyone help?

Thomas

I'll just add this too.. Normally when I create an application, the application folder appears in finder. When I create with -d msql, the application folder is hidden, but appears after running open ../biller

Dave Faliskie
Dave Faliskie
17,793 Points

Did you figure out what was wrong I'm having the same problem.

3 Answers

I found a fix to this:

1) Make sure you have mysql installed (check by running "mysql" in cmd prompt). I didn't and installed via home brew (http://brew.sh/).

2) Make sure the server has actually started.

mysql.server start

3) It's pretty likely that you'll need to create a user with the correct permissions and a database - I did this via the command line. Type

mysql

and you will open the mysql prompt. In the prompt you can run mysql commands. Use 'exit' to exit the prompt.

NOTE: If you're not the root user, you will have to start using

sudo mysql

to create a user and permissions (and the database but I can't quite remember).

4) If you're still having troubles, go to the database info in your application and change localhost to 127.0.0.1.

5) If you're using MAMP and php for other frameworks like laravel be aware you might need to change your php/mysql configuration to make everything work well. Some of my MAMP phpmyadmin stuff broken down after I did this - I think something to do with have two instances of mysql on my computer. I'm sure there's a straightforward fix for this, but haven't go to it #dontfixitunlessitsbroke!

There might be another step I've forgotten, but generally speaking, googling the error message gave me the answers I needed :-)

Hope this helps!

Dave Faliskie
Dave Faliskie
17,793 Points

Thanks for the detailed response. I didn't have mysql installed, and finally figured out everything with permissions.

awesome!

Eirik Thommessen
Eirik Thommessen
2,159 Points

You can double check if you have the right version of mysql. In your gemfile : gem 'mysql2', '~>0.3.13'

Then you run bundle

After it has (most probably loaded an earlier version of mysql) you run rake db:create again