Lazy symbol binding failed when creating ruby db - ruby-on-rails

I am trying to install ruby on rails, and everything is installed now so far, but when I try to create a database with rake db:create, I get a weird error:
dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_get_client_info
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace
Trace/BPT trap: 5
I am working on osx mountain lion latest update. Does anyone have the right solution for me?

You might try this.
sudo gem install mysql2 — –with-mysql-config=/usr/local/mysql/bin/mysql_config
Be sure to modify the mysql config path with the location for yours.
You can determine this with the following command.
locate mysql_config
Leverage the path given with the command above.

The messge is telling that you have linked wrong version 32 vs. 64
On OSX you can see all versions on mysql installed
cd /usr/local/
and find right config in /usr/local/mysql-xxxx/bin/mysql_config
In my case it was:
gem uninstall mysql2
sudo gem install mysql2 --
--with-mysql-config=/usr/local/mysql-5.5.27-osx10.6-x86_64/bin/mysql_config
As discussed here: https://www.ruby-forum.com/topic/1440086

There are numerous questions about this and at least as many answers that work some of the time but not others. After trying most of them I noticed that the gem was 64bit and the mysql installation was 32bit.
To fix it:
install the 64 bit mysql
set up the symbolic links in /usr/local to point to the 64 bit version
set the PATH and DYLD_LIBRARY_PATH in your profile to include the correct versions
uninstall the mysql2 gem
install the mysql2 gem
ruby now plays nicely with mysql!
I haven't included the exact code as this tends to vary with your environment.

I was having a hard time with this one.. I tried all of the answers above, so I can't really pinpoint what combination resulted in the fix. I already had mysql installed and had reinstalled from mysql's website. It finally started working after I followed the bellow.
This is on Mavericks using rails 4 and brew is installed
brew install mysql
I'm not recommending this process .. Just noting that it worked for me after hours of frustration.
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo gem uninstall mysql
gem uninstall mysql2
gem install mysql
gem install mysql2

You need to install 64 bit MySql server. Don't forget to re-install mysql gem.

I had two versions of mysql installed (32 & 64 bit) for some reason.
Make sure your $MYSQL environmental variable (most likely found in ~/.bash_profile or ~/.profile) is pointing at the 64 bit version.
Also make sure you point towards the correct the mysql install when your installing the gem as the other answers have mentioned.

I had same problem. mysql2 version was 0.4.9, downgraded it to 0.4.5 and problem solved

Related

Segmentation fault with Rails after upgrading to OS Sierra, possibly related to sqlite3 gem

After upgrading to OSX Sierra I am having an issue with random segmentation faults. It most commonly occurs when running rails test and I believe it is due to the sqlite3_adapter.
My present work around is to simply quit terminal and restart it. This works for about 1 or 2 rails test and by the third one I am almost guaranteed to get another segmentation fault.
Is anybody else having an issue with this or find a better workaround?
$ rails t
Running via Spring preloader in process 13817
/Users/USER/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27: [BUG] Segmentation fault at 0x00000000000110
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
Edit:
After digging into the sqlite3_adapter.rb, I see that the line causing the segmentation fault is the creation of a new SQlite3 database.
db = SQLite3::Database.new(
config[:database].to_s,
:results_as_hash => true
)
Edit 2:
Rather than quitting and restarting terminal, I have found that running:
spring stop
stops the problem temporarily. Not a solution, but a better work around.
Edit 3:
This appears to be a problem with Apple's supplied libsqlite3 not being fork safe. More info can be found here:
https://github.com/sparklemotion/sqlite3-ruby/issues/195
For now, I have created an alias at the bottom of my ~/.bashrc file:
alias ss='spring stop'
When the problem occurs, I can now type:
ss
and then rerun the test.
Looks like a patch has been issued! The patch will look for sqlite3 in your brew folder instead of using Apple's supplied version by default. Simply run:
bundle update
to get the latest version of sqlite3-ruby and if you don't already have sqlite3 installed in your homebrew directory, run:
brew install sqlite3
I had the same problem when upgrading to Sierra. A simple bundle update will do the trick! Hope this helps.
Try rebuilding the sqlite3 gem. It has native extensions, and recompiling them in the Sierra environment may fix the issue.
Run:
gem pristine sqlite3
Which should give output like:
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored sqlite3-1.3.10
Building native extensions. This could take a while...
Restored sqlite3-1.3.11
I've noticed that I get a segfault as well, when trying to run rails console --sandbox specifically. I found this other question that seemed to fix this issue; specifically running
xcode-select --install
seemed to resolve it. This is by no means scientifically proven yet, however I am now able to run a rails console and all tests without a ruby segment fault.
Same problem w/Sierra. None of the stuff on this page worked for me, i.e. gem pristine sqlite3, xcode-select --install, sqlite3; gem uninstall sqlite3; bundle update. I eventually completely uninstalled the Ruby version with rbenv uninstall 2.3.1, then reinstalled it. This worked. I have no idea why.
I faced the same issue, I upgraded sqlite3 gem to 1.3.12 and it helped
All the previous solutions didn't worked so I've fixed this way:
gem uninstall sqlite3
brew install sqlite3
gem install sqlite3 -- --with-sqlite3-include=/usr/local/Cellar/sqlite/3.15.2/include --with-sqlite3-lib=/usr/local/Cellar/sqlite/3.15.2/lib
(Check the version you have in Cellar)
This is a temporary fix and probably if update the bundle it will stop working and you will do it again but al least I can work on my machine

Rails server won't start on Mountain Lion [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

rake db:create command is not working. Why? [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

How to use "mysql2" gem in Rails 3 application on Windows 7?

I try to install the mysql2 gem on Windows 7 32-bit.
I run:
gem install mysql2
and I get the following error:
ERROR: Error installing mysql2:
The 'mysql2' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
Any ideas what could cause this error, and how to solve this ?
UPDATE
I did everything as described here, but I can't figure out the last step:
gem install mysql2 --
'--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.1\lib\opt"
--with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.1\include"'
I understand that I should change the paths to the correct paths in my system, but I can't find the lib\opt and the include directories in my WAMP MySQL installation. I use WAMP 2.1.
Please advise.
Here is a proper solution for anyone interested, that doesn't mess up your current installation of mysql server -
EDIT : Make sure you download the right version on MySQL server. :
if you intend to connect to a 6.0 or 5.5 server - download those binaries. I'm connecting to mysql 5.1 - hence my example. Also keep in mind latest mysql2 gem ( v 0.3.7) was tested against mysql server 6 - hence it keeps failing to build on windows for earlier versions. also make sure you use the right libmysql.dll in your ruby folder.
Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (From here)
Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.
Extract all the files from the zip file into the folder you just created.
now run this command
gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'
I just installed mysql2 gem v. 0.3.7
EDIT 1
One more thing: make sure you run the command in Command Prompt directly. As in not PowerShell or Consol2 - for some reason if you try that it will give you and error " invalid option" - has to do with the way -- is parsed.
EDIT 2
I just was doing a blank windows 7 install and one thing I ran into is that you need to add one more step to this: check to see if there is libmysql.dll in your ruby bin directory, if not copy one over from your mysql install. It should be of the same version as your mysql2 build.
THANK YOU! One note: I had to include the --platform=ruby option as well. Thus, the final entire command line was:
gem install mysql2 --platform=ruby -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'
When I tried it without the platform=ruby option, DevKit didn't run and it just installed the normal mysql2 gem - it even gave a warning message about mysql2 being built for 6.0.2. I uninstalled it (gem uninstall mysql2), then ran it again with --platform=ruby and it worked awesome!
Me: Windows 7 64bit, Ruby 1.9.3p125, Rails 3.2.1, MySQL 5.1.56
Well, i don't really use Windows, but what about downloading the DevKit from 'http://rubyinstaller.org/downloads' and following the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit' ?
Try XAMPP from apachefriends.org, be sure to download the full version and you will find "lib", "bin", "include" and other MySQL directories. For further details, refer to -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
You should execute the setup file again,and choose the modify option,then check the Developer Components.When it finish,you will found the include folder and the opt folder.
Not all mysql2 versions come with windows binaries.
Easiest way to install gem mysql2 on windows is to pick a version that includes win binaries.
Link to list of versions
Choose the latest version number that includes “x86-mingw32”
For example 0.3.11
To install it:
gem install mysql2 -v 0.3.11
or in the gemfile:
gem „mysql2“, „0.3.11“

Installing MySQL gem in Ruby

I can't seem to install the MySQL gem. I'm using this command:
ARCHFLAGS="-arch i386" gem install mysql --
--with-mysql-dir=/usr/local/mysql/
--with-mysql-config=/usr/local/mysql-5.1.50-osx10.6-x86/bin/mysql_config
The errors that I am getting seem to indicate that I have no headers and etc. Not sure where I can get those. I'm on Snow Leopard.
Any ideas?
I had massive problems with this as well on Snow Leopard, but this worked great for me: http://blog.m-schmidt.eu/2009/12/11/ruby-on-rails-mysql-on-mac-os-x-10-6-snow-leopard/. Good luck!
EDIT: you could also try using Homebrew, described as "the missing package manager for OSX". Some instructions on installing MySQL with Homebrew can be found here: http://solutions.treypiepmeier.com/2010/02/28/installing-mysql-on-snow-leopard-using-homebrew/
His instructions in this link have worked for me time and time again. master kain's awesome mysql
Oh, and you did install xcode right? From the disks before you did all this, cause that is where the headers are.

Resources