1

I'm kind of a newbie at rails, I have to make a small rails project for school, but somehow I can't even get my server to run, really promising start, hope someone can help me out ;-).

When I try to start my rails server, it gives me a load error:

/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
    from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler.rb:120:in `require'
    from /Users/sanderdeclerck1/Sites/simple_cms/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:28:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:28
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:27:in `tap'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:27
    from script/rails:6:in `require'
    from script/rails:6

I'm running rails 3.0.8, and ruby 1.8.7

Anyone got any suggestion?

edit: forgot to mention I'm on OS X 10.6.7

Sander Declerck
  • 2,455
  • 4
  • 28
  • 38

5 Answers5

1

I guess you're on OS X, so therefore you should install MySQL first before actually loading the mysql Gem.

Two options:

  1. Follow this guide here or this slightly older guide on how to set everything up (MySQL, Ruby and Rails). It should actually be enough if you install MySQL from the official website, but it involves a bit of fiddling around before from my experience.

  2. You can also install MySQL through Homebrew. Here's a guide for that. Note that you have to manually start it with

    launchctl load ~/Library/LaunchAgents/com.mysql.mysqld.plist
    
slhck
  • 36,575
  • 28
  • 148
  • 201
  • Oh, okay *then* that's a slightly different problem. Are you sure it's running? I've kinda seen the same error when not loading it with `launchctl` – slhck Jun 15 '11 at 08:51
  • Ye, I can access it using mysql workbench, so it's definitely running – Sander Declerck Jun 15 '11 at 08:54
  • Hm. Maybe [that](http://stackoverflow.com/questions/4546698/library-not-loaded-libmysqlclient-16-dylib-error-when-trying-to-run-rails-serve) helps. Or [that](http://stackoverflow.com/questions/991708/rails-mysql-and-snow-leopard) one. – slhck Jun 15 '11 at 08:57
  • This problem has nothing to do with the MySQL server not running. It's failing to load the shared object (or the dylib in Mac terms), presumably because it's not at a known location (or not installed at all). – d11wtq Jun 15 '11 at 09:41
  • @d11wtq Yeah, I'd just suggest to install again. – slhck Jun 15 '11 at 09:42
1

Try adding export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH to your ~/.profile. If your mysql install is not in /usr/local you will have to change that path.

Paul Nicholson
  • 557
  • 3
  • 15
0

If you use Ubuntu try to install apt-get install ruby-dev libmysql-ruby libmysqlclient-dev package

bor1s
  • 4,081
  • 18
  • 25
0

How did you install MySQL? You might need to specify --with-lib or --with-mysql-dir when installing the MySQL gem.

gem install mysql2 -- '--with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include'
d11wtq
  • 34,788
  • 19
  • 120
  • 195
0

you might just need to reinstall the mysql2 gem.

first you should find your mysql_config. you can do this by issuing:

sudo find /usr/local -name mysql_config

then install the gem with

(sudo) gem install mysql2 -- --with-mysql-config=RESULT_FROM_ABOVE

this should give you a gem that is configured with your mysql installation. Hope that helps.

Thomas Krajacic
  • 2,488
  • 1
  • 21
  • 25