Error starting rails server after creating new app using mysql [duplicate] - mysql

I've been struggling with this for some time.
I've installed Rails 3, gem, mysql on my Snow Leopard machine. All was going well until I created my first project and tried to run
rails server
Upon running this I get:
jontybrook$ rails server
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
from /Users/jontybrook/Dropbox/CODING/simple_cms/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
jontybrook$
As far as I can tell the problem is with the mysql2 gem. MySQL seems to be running fine and my Gemfile references mysql2, my database.yml file seems ok also.
The error mentions
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
And yet
jontybrook$ cd /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2
jontybrook$ ls
client.rb em.rb error.rb mysql2.bundle result.rb
MySQL2.bundle is there!?
If I use the old mysql gem, WEBrick boots fine. But that's not ideal, is it?
I've tried everything google can give me! Any help much appreciated.

I was never able to get any of these answers to work for me, but this is the command that I used to make it work for me. This way you don't need to use install_name_tool every time you update your mysql
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

I have solved this, eventually!
I re-installed Ruby and Rails under RVM. I'm using Ruby version 1.9.2-p136.
After re-installing under rvm, this error was still present.
In the end the magic command that solved it was:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

This fix worked very well for me:
Add the following to to your ~/.profile
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
http://www.rickwargo.com/2010/12/16/installing-mysql-5-5-on-os-x-10-6-snow-leopard-and-rails-3/

For me this was just because I had upgraded mysql but hadn't updated the mysql2 gem - a reinstall of the gem will fix it...
gem pristine mysql2

I have the same issue. It looks like it's unable to find the libmysqlclient library. A temporary fix that has worked for me is the following:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
I am not sure where the config is specifying the load path or what it's set to but my mysql install did not appear to be in it. I'll post again if I find a more permanent solution.
Edit:
Actually this fix appears to more accurately address the problem.

Add the below to your ~/.bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
This worked for me

In OSX El Capitan update when you do this:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
it throws an error like
ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted
So to avoid this, what you can do is first locate libmysqlclient.18.dylib using the command
User$ locate libmysqlclient.18.dylib
In my case it returned /usr/local/mysql-5.5.24-osx10.5-x86_64/lib/libmysqlclient.18.dylib
So instead of usr/lib/ we will create symlink to usr/local/lib/ like this :
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
More details : https://forums.developer.apple.com/thread/7935

following lines works for me. I am using mac 10.7.2 .
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Just ran into this problem. All I had to do is uninstall mysql2 gem and reinstall it. Hope this works for other people

This is how it worked for me:
I ran the below command
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
My environments:
$ rails -v
Rails 3.0.6
$ mysql --version
mysql Ver 14.14 Distrib 5.5.11, for osx10.6 (i386) using readline 5.1
$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
Hope this helps someone.

Thanks, Ogapo! Exporting that alias worked for me, and then I followed the link, and in my case the mysql2.bundle was up in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle so I adjusted the install_name_tool to modify that bundle rather than one in ~/.rvm and got that working the way it should be done.
So now:
$ otool -L /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
/usr/local/mysql/lib/libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)

hi it worked for me from the recommended link from Fredy Andersen
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql /lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
just had to change to my version of mysql, in the command,
thanks

I solved this problem by deleting my gemset for my current project and recreating it and rerunning bundle install. I think I caused it by installing a newer version of mysql.

I had this issue when working with Django, I use brew to install a lot of my Open Source programs and I needed to do the following since I used brew to install mysql:
sudo ln -s /usr/local/Cellar/mysql/5.5.20/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Be sure to replace with your version of the libraries!

bundle install mysql --force helped me. It reinstalled dependencies which ware gone as a result of brew uninstall mysql.

Jonty, I'm struggling with this too.
I think there's a clue in here:
otool -L /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
Notice the path to the dylib is, uh, rather short?
I'm trying to figure out where the gem install instructions are leaving off the dylib path, but it's slow going as I have never built a gem myself.
I'll post more if I find more!

I've had this exact same problem a few days ago. I eventually managed to solve it. I'm not quite sure how, but I'll tell you what I did anyway. Maybe it'll help you.
I started by downloading RVM. If you aren't using it yet, I highly recommend doing so. It basically creates a sandbox for a new separate installation of Ruby, RoR and RubyGems. In fact, you can have multiple installations simultaneously and instantly switch to one other. It works like a charm.
Why is this useful? Because you shouldn't mess with the default Ruby installation in OS X. The system depends on it. It's best to just leave the default Ruby and RoR installation alone and create a new one using RVM that you can use for your own development.
Once I created my separate Ruby installation, I just installed RoR, RubyGems and mysql, and it worked. For the exact steps I took, see my question: Installing Rails, MySQL, etc. everything goes wrong
Again: I don't know for certain this will solve your problem. But it certainly did the trick for me, and in any case using RVM is highly recommendable.

I still found that with the solutions above, it didn't work (for example) with the Rails plugin for TextMate. I got a similar error (when retrieving the database schema).
So what did is, open terminal:
cd /usr/local/lib
sudo ln -s ../mysql-5.5.8-osx10.6-x86_64/lib/libmysqlclient.16.dylib .
Replace mysql-5.5.8-osx10.6-x86_64 with your own path (or mysql).
This makes a symbol link to the lib, now rails runs from the command line, as-well as TextMate plugin(s) like ruby-on-rails-tmbundle.
To be clear: this also fixes the error you get when starting rails server.

This usually happen when you upgrade mysql. The installed mysql2 gem which was built on the old mysql libs cannot work with new libs. Just need to reinstall it.
Uninstall mysql2 with gem uninstall mysql2. Then install it with gem install mysql2

I've resolved it by creating .rvmrc file in my project folder containg:
rvm use <yourrubie>
then entering my project path
cd ~/myprojectpath
then I run
bundle install

My version of luvlss's command:
Mac OSX 10.10.5
MySQL 5.6.27
Passenger 5.0.21
sudo ln -s /usr/local/mysql-5.6.27-osx10.8-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
If you're trying lots of different links, like I did, do some clean-up with:
sudo unlink /usr/lib/libmysqlclient.18.dylib

Open a Terminal and run the following:
export PATH=$PATH:/usr/local/mysql/bin
It should work.

If you're using OSX and installed mysql using brew, you can:
brew link mysql
If you're having trouble with the version (I had mysql 5.7 running while my gem required 5.6.25), you can
brew unlink mysql
brew switch mysql 5.6.25

For me I had to manually uninstall mysql
brew uninstall mysql
rm -rf /usr/local/var/mysql
brew install mysql

Related

"rails s" can not be executed [duplicate]

I've been struggling with this for some time.
I've installed Rails 3, gem, mysql on my Snow Leopard machine. All was going well until I created my first project and tried to run
rails server
Upon running this I get:
jontybrook$ rails server
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
from /Users/jontybrook/Dropbox/CODING/simple_cms/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
jontybrook$
As far as I can tell the problem is with the mysql2 gem. MySQL seems to be running fine and my Gemfile references mysql2, my database.yml file seems ok also.
The error mentions
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
And yet
jontybrook$ cd /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2
jontybrook$ ls
client.rb em.rb error.rb mysql2.bundle result.rb
MySQL2.bundle is there!?
If I use the old mysql gem, WEBrick boots fine. But that's not ideal, is it?
I've tried everything google can give me! Any help much appreciated.
I was never able to get any of these answers to work for me, but this is the command that I used to make it work for me. This way you don't need to use install_name_tool every time you update your mysql
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I have solved this, eventually!
I re-installed Ruby and Rails under RVM. I'm using Ruby version 1.9.2-p136.
After re-installing under rvm, this error was still present.
In the end the magic command that solved it was:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
This fix worked very well for me:
Add the following to to your ~/.profile
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
http://www.rickwargo.com/2010/12/16/installing-mysql-5-5-on-os-x-10-6-snow-leopard-and-rails-3/
For me this was just because I had upgraded mysql but hadn't updated the mysql2 gem - a reinstall of the gem will fix it...
gem pristine mysql2
I have the same issue. It looks like it's unable to find the libmysqlclient library. A temporary fix that has worked for me is the following:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
I am not sure where the config is specifying the load path or what it's set to but my mysql install did not appear to be in it. I'll post again if I find a more permanent solution.
Edit:
Actually this fix appears to more accurately address the problem.
Add the below to your ~/.bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
This worked for me
In OSX El Capitan update when you do this:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
it throws an error like
ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted
So to avoid this, what you can do is first locate libmysqlclient.18.dylib using the command
User$ locate libmysqlclient.18.dylib
In my case it returned /usr/local/mysql-5.5.24-osx10.5-x86_64/lib/libmysqlclient.18.dylib
So instead of usr/lib/ we will create symlink to usr/local/lib/ like this :
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
More details : https://forums.developer.apple.com/thread/7935
following lines works for me. I am using mac 10.7.2 .
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Just ran into this problem. All I had to do is uninstall mysql2 gem and reinstall it. Hope this works for other people
This is how it worked for me:
I ran the below command
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
My environments:
$ rails -v
Rails 3.0.6
$ mysql --version
mysql Ver 14.14 Distrib 5.5.11, for osx10.6 (i386) using readline 5.1
$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
Hope this helps someone.
Thanks, Ogapo! Exporting that alias worked for me, and then I followed the link, and in my case the mysql2.bundle was up in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle so I adjusted the install_name_tool to modify that bundle rather than one in ~/.rvm and got that working the way it should be done.
So now:
$ otool -L /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
/usr/local/mysql/lib/libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
hi it worked for me from the recommended link from Fredy Andersen
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql /lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
just had to change to my version of mysql, in the command,
thanks
I solved this problem by deleting my gemset for my current project and recreating it and rerunning bundle install. I think I caused it by installing a newer version of mysql.
I had this issue when working with Django, I use brew to install a lot of my Open Source programs and I needed to do the following since I used brew to install mysql:
sudo ln -s /usr/local/Cellar/mysql/5.5.20/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Be sure to replace with your version of the libraries!
bundle install mysql --force helped me. It reinstalled dependencies which ware gone as a result of brew uninstall mysql.
Jonty, I'm struggling with this too.
I think there's a clue in here:
otool -L /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
Notice the path to the dylib is, uh, rather short?
I'm trying to figure out where the gem install instructions are leaving off the dylib path, but it's slow going as I have never built a gem myself.
I'll post more if I find more!
I've had this exact same problem a few days ago. I eventually managed to solve it. I'm not quite sure how, but I'll tell you what I did anyway. Maybe it'll help you.
I started by downloading RVM. If you aren't using it yet, I highly recommend doing so. It basically creates a sandbox for a new separate installation of Ruby, RoR and RubyGems. In fact, you can have multiple installations simultaneously and instantly switch to one other. It works like a charm.
Why is this useful? Because you shouldn't mess with the default Ruby installation in OS X. The system depends on it. It's best to just leave the default Ruby and RoR installation alone and create a new one using RVM that you can use for your own development.
Once I created my separate Ruby installation, I just installed RoR, RubyGems and mysql, and it worked. For the exact steps I took, see my question: Installing Rails, MySQL, etc. everything goes wrong
Again: I don't know for certain this will solve your problem. But it certainly did the trick for me, and in any case using RVM is highly recommendable.
I still found that with the solutions above, it didn't work (for example) with the Rails plugin for TextMate. I got a similar error (when retrieving the database schema).
So what did is, open terminal:
cd /usr/local/lib
sudo ln -s ../mysql-5.5.8-osx10.6-x86_64/lib/libmysqlclient.16.dylib .
Replace mysql-5.5.8-osx10.6-x86_64 with your own path (or mysql).
This makes a symbol link to the lib, now rails runs from the command line, as-well as TextMate plugin(s) like ruby-on-rails-tmbundle.
To be clear: this also fixes the error you get when starting rails server.
This usually happen when you upgrade mysql. The installed mysql2 gem which was built on the old mysql libs cannot work with new libs. Just need to reinstall it.
Uninstall mysql2 with gem uninstall mysql2. Then install it with gem install mysql2
I've resolved it by creating .rvmrc file in my project folder containg:
rvm use <yourrubie>
then entering my project path
cd ~/myprojectpath
then I run
bundle install
My version of luvlss's command:
Mac OSX 10.10.5
MySQL 5.6.27
Passenger 5.0.21
sudo ln -s /usr/local/mysql-5.6.27-osx10.8-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
If you're trying lots of different links, like I did, do some clean-up with:
sudo unlink /usr/lib/libmysqlclient.18.dylib
Open a Terminal and run the following:
export PATH=$PATH:/usr/local/mysql/bin
It should work.
If you're using OSX and installed mysql using brew, you can:
brew link mysql
If you're having trouble with the version (I had mysql 5.7 running while my gem required 5.6.25), you can
brew unlink mysql
brew switch mysql 5.6.25
For me I had to manually uninstall mysql
brew uninstall mysql
rm -rf /usr/local/var/mysql
brew install mysql

Ruby mysql2 gem compiled for wrong mysql client library version

After updating MySQL to 5.5 using apt-get, the mysql2 gem stopped working.
Here's the error:
Incorrect MySQL client library version!
This gem was compiled for 5.5.17 but the client library is 5.1.58. (RuntimeError)
I tried reinstalling with mysql_config but it doesn't seem to make a difference..
gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config
Correspondingly, I tried telling bundle to compile mysql2 with mysql-config but still, the error remains..
bundle config build.mysql2 --with-mysql-config=/usr/bin/mysql_config
bundle install
When I tried an older version of the gem (v0.2.6) the rails console opens but crashes once I run any type of query.
Here's the full error stack when trying the most current version of the mysql2 gem:
[marco#linode:/www] 07:29:00 AM: rails c
/users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in `require': Incorrect MySQL client library version! This gem was compiled for 5.5.17 but the client library is 5.1.58. (RuntimeError)
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in `<top (required)>'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
from /www/config/application.rb:7:in `<top (required)>'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:38:in `require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Edit: I removed all mysql2 gemspecs from cache, uninstalled all mysql-related packages via apt-get and reinstalled everything afresh, then tried again to install the gem with the mysql-config flag .. but it all proved futile. The error remains.
Edit 2: As suggested by John Bachir, I confirmed that mysql_config contains MySQL version 5.5.
Late to the party, but I just did
gem uninstall mysql2
gem install mysql2
Gem path was
$ bundle show mysql2
/var/lib/gems/1.9.1/gems/mysql2-0.3.16
I have encounter the same error when using Ubuntu Server 11.04 and Percona Server, what have I done was:
replace /usr/lib/libmysqlclient.so.16.0.0 with /usr/lib/libmysqlclient.so.18.0.0
I had this problem and just needed to recompile the gem. I don't know if there's a more programmatic way with bundler, but I just removed the compiled gem and then re-ran bundler:
$ bundle show mysql2
/usr/local/rvm/gems/ruby-1.9.3-p385/bundler/gems/mysql2-32dd7e5bbeba
$ rm -rf /usr/local/rvm/gems/ruby-1.9.3-p385/bundler/gems/mysql2-32dd7e5bbeba
$ bundle
I came across a similar problem:
Incorrect MySQL client library version! This gem was compiled for 5.6.12 but the client library is 5.5.28.
And my MySQL version on Mac:
$ mysql --version
mysql Ver 14.14 Distrib 5.6.12, for osx10.8 (x86_64) using EditLine wrapper
and the mysql2 gem installed by bundle install is mysql2-0.3.13
I solved this problem by just setting the mysql2 gem to an older version in the Gemfile:
gem 'mysql2', '0.2.6'
If '0.2.6' does not work for you, you could try another old version number.
Rather than moving library files, you might also check the package list for your system -- if you upgraded to 5.5 using apt-get, it's likely that you still have 5.1 libraries lying around that you don't need anymore at all. For example, on a system where we encountered a similar issue, we still had the 5.1 library:
$ sudo dpkg -l | grep mysql
ii libmysqlclient-dev 5.5.13-rel20.4-136.lucid Percona Server database development files
ii libmysqlclient16 5.1.61-rel13.2-431.lucid Percona Server database client library
ii libmysqlclient18 5.5.13-rel20.4-136.lucid Percona Server database client library
Rather than copying the 5.5 library over the 5.1 library, you should be able to remove it:
$ sudo apt-get remove libmysqlclient16
For us, this has been more reliable than the library renaming solution proposed earlier.
I meet this problem again and I could not solve it with my previous method(use an older version mysql2 gem). So I try another method as these step:
1.find which mysql_config that your gem library depend on.
mysql_config situation is different in different people's machine, and one people machine can have several mysql_config, so there is no standard mysql_config path for everyone.
As this question for example, the mysql_config version is "5.1.58", so you can search "mysql" file in root to find which has related with "5.1.58":
cd /
sudo find -name "mysql" ./
2.install mysql2 gem library again with specific mysql_config path find in step 1
gem install mysql2 -- --with-mysql-config=<%your_specific_mysql_config_path%>
Other than making sure that only the libmysqlclient18 library was installed (and not 16), what made it work for me was installing libmysqlclient18-dev (the dev headers).
This is with Percona Server 5.5 on Ubuntu Precise.
I tried all the answers above and my final approach was fairly simple -- delete the entire bundled gem stack and reinstall everything. That finally got around the mysql client issue. i.e.
rm -rf /Users/sjohnson/.rvm/gems/ruby-1.9.3-p484#adp_rails3
bundle install
if you know c program,you can remove this message. omit it.
open this mysql.gem mysql-2.9.1.gem\data.tar.gz\data.tar\ext\mysql_api\mysql.c
find "This gem was compiled for" ,delete this if sentence .
if (lib[i] != MYSQL_SERVER_VERSION[i]) { Line 1897: rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_SERVER_VERSION, lib); }
you need set sys-variable for local gemfile install on windows system . SET HOMEDRIVE=c:
ERROR: While executing gem ... (Errno::EINVAL) Invalid argument # rb_file_s_stat - U:/
install local gem file . C:\Rails>gem install --local mysql-2.9.1.gem --install-dir=c:/tmp --platform= ruby -- --with-mysql-dir=C:/Rails/mysql-connector-c
mysql-connector-c visit mysql http://dev.mysql.com/downloads/connector/c/ . you don't care version.
try again.
require 'mysql'
On Mac using Brew verify the versions installed on your machine:
ls /usr/local/Cellar/mysql*
Them remove the wrong version such as:
brew uninstall mysql-client
Remove the gem:
gem uninstall mysql2
Run bundle again:
bundle install
Make sure that /usr/bin/mysql_config is indeed the one that came with 5.5.
In my case, I had various files from libmysqlclient15 (dated 2009) and libmysqlclient16 (dated 20012) left in /usr/lib, possibly from a botched Ubuntu upgrade.
Removing the libmysqlclient15 files (which were linked to libmysqlclient15.so) solved my problem.
On my machine I had to uninstall the gem, then re-direct the symlink /usr/local/mysql to the correct Homebrew version:
ln -s /usr/local/bin/mysql /usr/local/mysql
Then run bundle install.
Reinstall libmysqlclient-dev with apt remove libmysqlclient-dev && apt install libmysqlclient-dev fixed for me
This is for anyone that stumble upons this question after 11 years.
Finally figured out that an update on mariadb-connector-c caused my rails fail to start up with a Bundler::GemRequireError.
It was complaining with the following:
Gem Load Error is: Incorrect MySQL client library version! This gem was compiled for 10.6.8-MariaDB but the client library is 3.2.7.
The version numbers that are suggested in the error are widely different, which felt strange. This wasn't a new install, my dev env was working for months.
After going through all sorts of hoops, depleting SO resources and even getting some AI involved, I finally tried downgrading the package. (My next step was going to be removing MariaDB altogether, but fortunately we didn't come to that)
sudo dnf downgrade mariadb-connector-c-3.1.13-2.fc35 --allowerasing
I verified that the mysql cc_version went down
/usr/bin/mysql_config
Then I removed and installed the gem
gem uninstall mysql2
gem install mysql2 -v '0.3.21' -- --with-mysql-config=/usr/bin/mysql_config
That's it. rails was working again.
FYI: I am on Fedora 35; I use RVM; and the rails version was 4.2
A couple of things that may fix some other people's issues:
Reinstalling Gem:
gem uninstall mysql2
gem pristine mysql2 or bundle install or gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'
Checking Package History:
dnf history provides a list of recent dnf changes... some have empty fields in "Command Line" column...
those still have updates, etc in them... you can refer to them with
dnf history info <ID>

Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem

I've been struggling with this for some time.
I've installed Rails 3, gem, mysql on my Snow Leopard machine. All was going well until I created my first project and tried to run
rails server
Upon running this I get:
jontybrook$ rails server
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
from /Users/jontybrook/Dropbox/CODING/simple_cms/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
jontybrook$
As far as I can tell the problem is with the mysql2 gem. MySQL seems to be running fine and my Gemfile references mysql2, my database.yml file seems ok also.
The error mentions
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
And yet
jontybrook$ cd /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2
jontybrook$ ls
client.rb em.rb error.rb mysql2.bundle result.rb
MySQL2.bundle is there!?
If I use the old mysql gem, WEBrick boots fine. But that's not ideal, is it?
I've tried everything google can give me! Any help much appreciated.
I was never able to get any of these answers to work for me, but this is the command that I used to make it work for me. This way you don't need to use install_name_tool every time you update your mysql
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I have solved this, eventually!
I re-installed Ruby and Rails under RVM. I'm using Ruby version 1.9.2-p136.
After re-installing under rvm, this error was still present.
In the end the magic command that solved it was:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
This fix worked very well for me:
Add the following to to your ~/.profile
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
http://www.rickwargo.com/2010/12/16/installing-mysql-5-5-on-os-x-10-6-snow-leopard-and-rails-3/
For me this was just because I had upgraded mysql but hadn't updated the mysql2 gem - a reinstall of the gem will fix it...
gem pristine mysql2
I have the same issue. It looks like it's unable to find the libmysqlclient library. A temporary fix that has worked for me is the following:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
I am not sure where the config is specifying the load path or what it's set to but my mysql install did not appear to be in it. I'll post again if I find a more permanent solution.
Edit:
Actually this fix appears to more accurately address the problem.
Add the below to your ~/.bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
This worked for me
In OSX El Capitan update when you do this:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
it throws an error like
ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted
So to avoid this, what you can do is first locate libmysqlclient.18.dylib using the command
User$ locate libmysqlclient.18.dylib
In my case it returned /usr/local/mysql-5.5.24-osx10.5-x86_64/lib/libmysqlclient.18.dylib
So instead of usr/lib/ we will create symlink to usr/local/lib/ like this :
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
More details : https://forums.developer.apple.com/thread/7935
following lines works for me. I am using mac 10.7.2 .
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Just ran into this problem. All I had to do is uninstall mysql2 gem and reinstall it. Hope this works for other people
This is how it worked for me:
I ran the below command
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
My environments:
$ rails -v
Rails 3.0.6
$ mysql --version
mysql Ver 14.14 Distrib 5.5.11, for osx10.6 (i386) using readline 5.1
$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
Hope this helps someone.
Thanks, Ogapo! Exporting that alias worked for me, and then I followed the link, and in my case the mysql2.bundle was up in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle so I adjusted the install_name_tool to modify that bundle rather than one in ~/.rvm and got that working the way it should be done.
So now:
$ otool -L /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
/usr/local/mysql/lib/libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
hi it worked for me from the recommended link from Fredy Andersen
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql /lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
just had to change to my version of mysql, in the command,
thanks
I solved this problem by deleting my gemset for my current project and recreating it and rerunning bundle install. I think I caused it by installing a newer version of mysql.
I had this issue when working with Django, I use brew to install a lot of my Open Source programs and I needed to do the following since I used brew to install mysql:
sudo ln -s /usr/local/Cellar/mysql/5.5.20/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Be sure to replace with your version of the libraries!
bundle install mysql --force helped me. It reinstalled dependencies which ware gone as a result of brew uninstall mysql.
Jonty, I'm struggling with this too.
I think there's a clue in here:
otool -L /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
libmysqlclient.16.dylib (compatibility version 16.0.0, current version 16.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
Notice the path to the dylib is, uh, rather short?
I'm trying to figure out where the gem install instructions are leaving off the dylib path, but it's slow going as I have never built a gem myself.
I'll post more if I find more!
I've had this exact same problem a few days ago. I eventually managed to solve it. I'm not quite sure how, but I'll tell you what I did anyway. Maybe it'll help you.
I started by downloading RVM. If you aren't using it yet, I highly recommend doing so. It basically creates a sandbox for a new separate installation of Ruby, RoR and RubyGems. In fact, you can have multiple installations simultaneously and instantly switch to one other. It works like a charm.
Why is this useful? Because you shouldn't mess with the default Ruby installation in OS X. The system depends on it. It's best to just leave the default Ruby and RoR installation alone and create a new one using RVM that you can use for your own development.
Once I created my separate Ruby installation, I just installed RoR, RubyGems and mysql, and it worked. For the exact steps I took, see my question: Installing Rails, MySQL, etc. everything goes wrong
Again: I don't know for certain this will solve your problem. But it certainly did the trick for me, and in any case using RVM is highly recommendable.
I still found that with the solutions above, it didn't work (for example) with the Rails plugin for TextMate. I got a similar error (when retrieving the database schema).
So what did is, open terminal:
cd /usr/local/lib
sudo ln -s ../mysql-5.5.8-osx10.6-x86_64/lib/libmysqlclient.16.dylib .
Replace mysql-5.5.8-osx10.6-x86_64 with your own path (or mysql).
This makes a symbol link to the lib, now rails runs from the command line, as-well as TextMate plugin(s) like ruby-on-rails-tmbundle.
To be clear: this also fixes the error you get when starting rails server.
This usually happen when you upgrade mysql. The installed mysql2 gem which was built on the old mysql libs cannot work with new libs. Just need to reinstall it.
Uninstall mysql2 with gem uninstall mysql2. Then install it with gem install mysql2
I've resolved it by creating .rvmrc file in my project folder containg:
rvm use <yourrubie>
then entering my project path
cd ~/myprojectpath
then I run
bundle install
My version of luvlss's command:
Mac OSX 10.10.5
MySQL 5.6.27
Passenger 5.0.21
sudo ln -s /usr/local/mysql-5.6.27-osx10.8-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
If you're trying lots of different links, like I did, do some clean-up with:
sudo unlink /usr/lib/libmysqlclient.18.dylib
Open a Terminal and run the following:
export PATH=$PATH:/usr/local/mysql/bin
It should work.
If you're using OSX and installed mysql using brew, you can:
brew link mysql
If you're having trouble with the version (I had mysql 5.7 running while my gem required 5.6.25), you can
brew unlink mysql
brew switch mysql 5.6.25
For me I had to manually uninstall mysql
brew uninstall mysql
rm -rf /usr/local/var/mysql
brew install mysql

Rails, MySQL and Snow Leopard

I upgraded to Snow Leopard using the disc we got at WWDC.
Trying to run some of my rails apps now complains about sql
(in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/
-- AdirondackPeepers.caf
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
(See full trace by running task with --trace)
I could have sworn I fixed this once before. The problem is that
sudo gem install mysql
does not work and gives the error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Has anybody gotten mysql to work with rails on snow leopard yet? If so, what is your setup and better yet, what can I do to reproduce it?
I just went through the same pain... here's what worked for me:
Download / install the 64-bit MySQL 5.1.37 from mysql.com
run the following commands:
sudo gem update --system
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I also uninstalled all mysql gems that were floating around from my 10.5 days, that may do it if the above doesn't work for you :)
Rebuilding mysql as 64bit or installing the 64bit version is important, but you also need to make sure you build the native parts of the mysql gem as 64bit as well (this doesn't apply if you are on one of the original Intel Core Duo macs).
Here's the magic command:
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
You should set the ARCHFLAGS as shown above whenever you do a gem install with native components on Snow Leopard.
If you're using bundler, you can use "bundle config" to set the proper build arguments for mysql like so:
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
I fought with this for a long time and finally got it working on Snow Leopard. I ended up installing Ruby, RubyGems, and MySQL from source (see the Hivelogic tutorial for installing Ruby and RubyGems. The MySQL tutorial is linked at the bottom). I finally got the gem to install, but I was still getting
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
Trace/BPT trap
I finally deleted the mysql.bundle (I have no idea what this is for) and it all worked.
sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Hope that helps someone.
I have seen this problem many times. almost everytime I build mysql on a machine. I think, you have to pass your mysqlconfig as part of the gem install command.
sudo gem install mysql -- --with-mysql-config=/your/mysql/config
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-mysql-config
Remember that you need mysql dev files to be able to build this gem.
I was having problems with getting my configuration to work after installing snow leopard. I found MAMP at http://www.mamp.info and it bundles Apache, PHP and MySQL. you install it like an application and it just works. Maybe worth giving it a try, and it is free.
mesh
I thought I would answer my own question here. It seems as if the problem isnt in mysql, but in the mysql ruby bindings. I figured this out because when I hooked up Querius (my mysql gui), it was able to connect.
Here is how to build from source fix the bindings:
cd /tmp
wget http://www.tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz
tar xvfz ruby-mysql-0.2.6.tar.gz
cd ruby-mysql-0.2.6
./configure
make
sudo make install
There are plenty of libraries that I will have to build from source on Snow Leopard and they keep popping up. MacPorts doesnt seem to be updated enough for all the libs so I'm off to do it on my own. Next up: freetype (http://download.savannah.gnu.org/releases-noredirect/freetype/)
I proceeded like explained in this post (http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/), and everything now works fine.
Remember to lookout for the typos in his command to install the mysql driver.
I had this same issue and here is what worked for me.
Install Snow Leopard and the 64bit MySQL DMG.
Create /etc/my.cnf to point to my previous MySQL data directory (as described here) and run sudo mysql_upgrade.
Opened IRB and reinstall all of my gems using (via blog.costan.us/2009/07/rebuild-your-ruby-gems-if-you-update-to.html).`gem list`.each_line {|line| system 'sudo gem install #{line.split.first}'}
Uninstalled the MySQL gems I had installed.
Installed MySQL gem with sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
With that, everything seems to be working so far. *knock wood*
In case you prefer homebrew, instead of installing MySQL manually.
Un-install the existing mysql gem (if any):
sudo gem uninstall mysql
Locate the ‘mysql_config’ file:
find /usr -name 'mysql_config'
Re-install mysql gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/bin/mysql_config
Note: replace /usr/local/bin/ with the corresponding mysql_config path found in step 2. Also on my blog.
Ian Selby thank you alot but I had to remove the sudo from in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.
I've solved it this way:
after install dmg file of mysql
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
env ARCHFLAGS="-arch x86_64"
bundle install
Having had a break from Rails for several years, I just spent some time setting up my development environment. So thought I would create a tutorial on how to install the latest version of Rails 3, MySQL, and RVM on SnowLeopard, to hopefully save others some time who are in my position.
It works as of 21st August 2011, using Rails 3.0.10, MySQL 5.5.15, and RVM 1.7.2. It should work with future Rails 3.0.x, MySQL 5.5.x, and RVM 1.7.x versions.
Install XCode if not already installed. I used 4.0.2. Unfortunately this has now been withdrawn by Apple, but may be available elsewhere on the Internet. Version 3.2.x is free to download from Apple, but I did not test it with this tutorial, it probably works too.
Install rvm:
user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
user$ source .bash_profile
Install a version of Ruby (e.g. 1.9.2) in rvm, basic usage instructions are here.
user$ rvm install 1.9.2
user$ rvm use 1.9.2
Create a gemset for the rvm ruby installed in step 2 (x is the version number).
user$ rvm gemset create rails30x
user$ rvm 1.9.2#rails30x
Install Rails 3.0.x (x is the version number).
user$ gem install rails -v 3.0.x.
Download and install the MySQL 5.5.x package, the startup item, and the preferences pane. All 3 of these are included in the DMG install file. Also install MySQL WorkBench.
Find /usr/local/mysql-version-name/support-files (inserting the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46 locate the lines that read:
basedir=
datadir=
and change them to read (inserting the correct MySQL directory name):
basedir=/usr/local/mysql-version-name
datadir=/usr/local/mysql-version-name/data
Save the file. MySQL can now be started from the preferences pane.
To enable rails 3 to use mysql, install the mysql2 gem (see next step). First, you’ll need to set the
DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile in your
home folder and include the following (inserting the correct MySQL directory name):
export DYLD_LIBRARY_PATH=/usr/local/mysql-version-name/lib:$DYLD_LIBRARY_PATH
Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library
would appear and the server would abort.
Install the mysql2 gem. (as of May 2011, version 0.2.7 is the most recent working version with Rails 3.0.x).
user$ gem install mysql2 -v 0.2.7
Create a rails app, and it's corresponding database (appname_development).
user$ rails new appname
Add this to the app's Gemfile: gem 'mysql2', "0.2.7"
Add this to the app's database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: appname_development
pool: 5
username: username
password: pwd
host: localhost
start app and check "About your application's environment". Everything should be working correctly.
The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:
DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
to my bash profile, and this solved it for me.
I tried the archflags trick many times with slight variations but it never worked for me.
What finally did work was switching back to the version of ruby and gem installed with snow leopard.
I had built and installed my own version which has worked for me in every respect except this one.
Since everything else seems to work fine, I can't help guessing the mysql plugin has some funky assumptions in it. Anyway, all I did was switch /usr/bin to be first in my path again. I had installed ruby in /usr/local/ruby-1.8.7 and /usr/local/ruby-1.9.1 to be able to easily switch. Thought I'd mention it since the archflags solution seems to work for many people, but not quite all.
I renamed the mysql_config program from $MYSQL_HOME/bin to something else so that the configuration script from the gem installer is unable to find it. Even though I was using the libs option, the gem installer did always use the compile settings from my mysql installation, which is fat binary. But the default ruby installation is only x86_64 and therefore the compile of the gem fails. After renaming the mysql_config program the following command worked just fine and installed the gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql
If you are installing the mysql gem with RVM you need to use the following code to install it
sudo env ARCHFLAGS="-arch x86_64" gem install mysql
This method worked for me in Leopard Server, none of the above worked
this article solved the issue for me :)
http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html
Prior to Leopard
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
Leopard on a PPC machine:
sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Leopard on an Intel machine:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Snow Leopard (only on Intel):
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

How do I install the mysql ruby gem under OS X 10.5.4

Here is the deal.
$ gem --version
1.1.0
$ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Bulk updating Gem source index for:
http://gems.rubyforge.org/ ERROR:
could not find mysql locally or in a
repository
$ sudo gem update
Updating installed gems Bulk updating
Gem source index for:
http://gems.rubyforge.org/
Updating
RedCloth ERROR: While executing gem
... (Gem::GemNotFoundException)
could not find RedCloth locally or in a repository
I've tried this, this, this, this, and a ton of others.
None of them have worked for me. Is anyone else having this problem? If so what did you do to fix it that is not mentioned above?
First of all as Orion Edwards said make sure you have rubygems 1.2. Unfortunately,
gem update --system
did not work for me.
Instead I had to:
Manually download rubygems-update-1.2.0 from rubyforge.
$ sudo gem install /path/to/rubygems-update-1.2.0.gem
$ update_rubygems
Now that I had rubygems 1.2 I ran
$ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Everything is working. Thanks Orion Edwards for steering me in the right direction.
Step 1
gem update --system
It probably won't provide the fix itself, but You really want rubygems 1.2. It will save you about 8 days waiting as it doesn't need to do the 'Bulk updating 102304 gems' rubbish any more
It actually looks like it can't find the mysql gem at all, let alone download or install it. You're not behind a proxy server or something weird like that?
If it's something to do with your rubygems or the net, rather than mysql specifically, then the gem update --system should reveal it too
Do you have different ruby versions on your system? If you're running the Darwin-supplied ruby binary, but installed ruby gems under /usr/local, then you'll get errors like this. Even if you've aliased ruby to point to /usr/local, the gem command may fail if the proper ruby binary is not resolved correctly by your shell's $PATH. Also, if /usr/local/bin is located physically after /usr/bin in your path, gem will use /usr/bin/ruby to load the gems from /Library/Ruby/Gems/1.8/gems/. You may want to symlink /usr/lib/ruby/gems/1.8/gems to /Library/Ruby/Gems/1.8/gems/ to prevent this sort of thing.
Ryan Grove has a blog post with the answer:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
Installing XCode solved this problem for me.
This is because it includes the make and gcc tools, which are required by the gem.