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

kabir k
PLUS
kabir k
Courses Plus Student 18,036 Points

LoadError (rake aborted!) when running the `rake db:create` command in the terminal

I got a LoadError (rake aborted!) when I tried to run the rake db:create command in the terminal.

This is the error I got from the terminal

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

Can anyone help figure out what's going on?

I'm on a Mac and I have MySQL server running.

3 Answers

Hopefully you got this fixed but if not, I ran into the same issue and fixed it this morning with the following terminal command:

"sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib"

It creates a symbolic link in the directory that rails is looking for the "missing" file. You will likely run into another issue after this (unless a fix has been provided by the time you've read this post) in which case you will have to change a line in your Gemfile.

Change the line "gem 'mysql2'" to:

gem 'mysql2', '~> 0.3.18'

The most recent version of Rails 4 is ahead of the newest version of the mysql gem so this change will explicitly set the version of mysql being used to a compatible version. Hope this helps!

Timothy Boland
Timothy Boland
18,237 Points

I get the following when i run your recommendation:

ln: /usr/lib/libmysqlclient.20.dylib: Operation not permitted
Jamie Perlmutter
Jamie Perlmutter
10,955 Points

In the questions for the video there are a few macs that have this problem I'd suggest looking through to find which one sounds close to your issue. I am running windows, I know for me the problem was that I had to change the PATH as well as make sure that I put in my password when it prompted. I also in the Gemfile had to specify which version of mysql, so I added '~> 0.3.18' it helped me, I ran into password issues after (good old windows permission blockinghaha) so I googled a ton to find out the issue. If all else fails let me know and we'll take another crack at it.

kabir k
kabir k
Courses Plus Student 18,036 Points

Thanks Jamie, for your response but unless there are specific steps to follow, I don't know where to start to fix the problem.