EzDevInfo.com

mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql brianmario/mysql2 · GitHub mysql2 - a modern, simple and very fast mysql library for ruby - binding to libmysql

mysql2 gem compiled for wrong mysql client library

When try to connect to the mysql server through my rails application, I get the following error

D:/Program_Files/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.0.27. (RuntimeError)

How can I rectify it?


Source: (StackOverflow)

ERROR: Failed to build gem native extension (mysql2 on rails 3.2.3)

I'm trying to install the mysql2 gem with Rails 3.2.3 and it's failing:

★  bundle install
Fetching gem metadata from https://rubygems.org/.........
Using rake (0.9.2.2) 
Using i18n (0.6.0) 
Using multi_json (1.2.0) 
Using activesupport (3.2.3) 
Using builder (3.0.0) 
Using activemodel (3.2.3) 
Using erubis (2.7.0) 
Using journey (1.0.3) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.2) 
Using actionpack (3.2.3) 
Using mime-types (1.18) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.3) 
Using arel (3.0.2) 
Using tzinfo (0.3.32) 
Using activerecord (3.2.3) 
Using activeresource (3.2.3) 
Using bundler (1.1.3) 
Using coffee-script-source (1.2.0) 
Using execjs (1.3.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.6.6) 
Using rdoc (3.12) 
Using thor (0.14.6) 
Using railties (3.2.3) 
Using coffee-rails (3.2.2) 
Using jquery-rails (2.0.2) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
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
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-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=/Users/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /Users/rarneson/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/rarneson/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.

I'm running bundle install and this is in my Gemfile:

gem 'mysql2', '~> 0.3.11' 

I've currently got MySQL running through MAMP. I'm not sure if this is a bad idea and I should run a vanilla MySQl but it seems my current problem is just getting the gem installed. I've seen quite a few of these problems here on stackoverflow but all seem a bit different or have really complicated solutions. Is there something I'm missing? Something simple? Something stupid? I can provide additional info from the out file if necessary. I've read that some people use SQLite for dev and test then MySQL in prod but that sounds like a pretty horrible idea.


Source: (StackOverflow)

Advertisements

Please install mysql adapter 'gem install activerecord-mysql-adapter'

I'm having trouble finding a solution to this problem. I'm getting the error:

Please install the mysql adapter: 'gem install activerecord-mysql-adapter'

 /Users/ Andy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:143:in `block in replace_gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (LoadError)
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/mysql_adapter.rb:5:in `<top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:48:in `resolve_hash_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/ Andy /config/environment.rb:5:in `<top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /config.ru:4:in `block in <main>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/ Andy /config.ru:1:in `new'
    from /Users/ Andy /config.ru:1:in `<main>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:46:in `app'
    from /Users/ Andy/mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:70:in `start'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>' ```

Here is the gem env output.

  RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.15
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.2.0]
  - INSTALLATION DIRECTORY: /Users/ Andy/.rvm/gems/ruby-1.9.2-p290
  - RUBY EXECUTABLE: /Users/ Andy/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/ Andy/.rvm/gems/ruby-1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/ Andy/.rvm/gems/ruby-1.9.2-p290
     - /Users/ Andy/.rvm/gems/ruby-1.9.2-p290@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

If I can provide any more information please let me know.

Thanks, -Andy


P.s - My database.yaml already has mysql2.


Source: (StackOverflow)

bundle install problem: mysql.h is missing

in my mac OSX 10.6 32 bit, I can install mysql2 gem quite easily, but not in mini mac 10.6 64bit server.

I have installed MySQL 5.5.11 in troublesome server, while in my home mac MySQL 5.5.0.m2 Somehow when I run bundle install, in server it tries to install mysql2.0.3.2 while in home mysql2.0.2.6

Please don't tell me to

env ARCHFLAGS="-arch x86_64" sudo gem install mysql2 --version '= 0.2.6' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I tried that, doesn't work.

Included /usr/local/mysql/bin in $PATH does not help as well.

Error code:

    Installing mysql2 (0.3.2) with native extensions /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

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=/Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2 for inspection.
Results logged to /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/ext/mysql2/gem_make.out
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:511:in `block in build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `each'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:159:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/source.rb:96:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:55:in `block in run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:44:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:8:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/cli.rb:225:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/bin/bundle:13:in `<top (required)>'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `load'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `<main>'

Source: (StackOverflow)

Install mysql2 gem on Snow Leopard for Rails 3 with rvm

I have recently upgraded to Rails 3 and created a new application with Rails 3.0.3, but I keep getting an error

Macintosh:$ rails server
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-11-28 11:32:47] INFO  WEBrick 1.3.1
[2010-11-28 11:32:47] INFO  ruby 1.8.7 (2010-04-19) [i686-darwin10.4.0]
[2010-11-28 11:32:47] INFO  WEBrick::HTTPServer#start: pid=1055 port=3000


Started GET "/" for 127.0.0.1 at Sun Nov 28 11:32:52 +0000 2010

RuntimeError (!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'):


I have a 64 bits machine. Errors are only on documentation and looked like the gem was installed correctly.

Macintosh:$ env ARCHFLAGS="-arch i386" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Building YARD (yri) index for mysql2-0.2.6...
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known

I have added the gem in my GemFile

source 'http://rubygems.org'

gem 'rails', '3.0.3'
gem 'mysql2'
gem 'sqlite3-ruby', :require => 'sqlite3'

My GemFile.lock looks like this

GEM
  remote: http://rubygems.org/
  specs:
    abstract (1.0.0)
    actionmailer (3.0.3)
      actionpack (= 3.0.3)
      mail (~> 2.2.9)
    actionpack (3.0.3)
      activemodel (= 3.0.3)
      activesupport (= 3.0.3)
      builder (~> 2.1.2)
      erubis (~> 2.6.6)
      i18n (~> 0.4)
      rack (~> 1.2.1)
      rack-mount (~> 0.6.13)
      rack-test (~> 0.5.6)
      tzinfo (~> 0.3.23)
    activemodel (3.0.3)
      activesupport (= 3.0.3)
      builder (~> 2.1.2)
      i18n (~> 0.4)
    activerecord (3.0.3)
      activemodel (= 3.0.3)
      activesupport (= 3.0.3)
      arel (~> 2.0.2)
      tzinfo (~> 0.3.23)
    activeresource (3.0.3)
      activemodel (= 3.0.3)
      activesupport (= 3.0.3)
    activesupport (3.0.3)
    arel (2.0.4)
    builder (2.1.2)
    erubis (2.6.6)
      abstract (>= 1.0.0)
    i18n (0.4.1)
    mail (2.2.10)
      activesupport (>= 2.3.6)
      i18n (~> 0.4.1)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.16)
    mysql2 (0.2.6)
    polyglot (0.3.1)
    rack (1.2.1)
    rack-mount (0.6.13)
      rack (>= 1.0.0)
    rack-test (0.5.6)
      rack (>= 1.0)
    rails (3.0.3)
      actionmailer (= 3.0.3)
      actionpack (= 3.0.3)
      activerecord (= 3.0.3)
      activeresource (= 3.0.3)
      activesupport (= 3.0.3)
      bundler (~> 1.0)
      railties (= 3.0.3)
    railties (3.0.3)
      actionpack (= 3.0.3)
      activesupport (= 3.0.3)
      rake (>= 0.8.7)
      thor (~> 0.14.4)
    rake (0.8.7)
    sqlite3-ruby (1.2.4)
    thor (0.14.6)
    treetop (1.4.9)
      polyglot (>= 0.3.1)
    tzinfo (0.3.23)

PLATFORMS
  ruby

DEPENDENCIES
  mysql2
  rails (= 3.0.3)
  sqlite3-ruby

Gem list

Macintosh:$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.3)
actionpack (3.0.3)
activemodel (3.0.3)
activerecord (3.0.3)
activeresource (3.0.3)
activesupport (3.0.3)
acts_as_ferret (0.4.4)
arel (2.0.4)
builder (3.0.0, 2.1.2)
bundler (1.0.7)
capistrano (2.5.9)
dnssd (1.3)
erubis (2.6.6)
fastthread (1.0.7)
gnuplot (2.2)
highline (1.6.1, 1.5.1)
hpricot (0.8.1)
i18n (0.4.2, 0.4.1)
libxml-ruby (1.1.3)
linecache (0.43)
mail (2.2.10)
memcache-client (1.8.5, 1.7.6)
memcached (0.17.5)
mime-types (1.16)
mysql2 (0.2.6)
net-scp (1.0.4, 1.0.2)
net-sftp (2.0.5, 2.0.2)
net-ssh (2.0.23, 2.0.15)
net-ssh-gateway (1.0.1)
polyglot (0.3.1)
rack (1.2.1, 1.0.1, 1.0.0)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (3.0.3)
railties (3.0.3)
rake (0.8.7, 0.8.4)
rcov (0.9.9, 0.9.8)
rdoc (2.5.11)
RedCloth (4.2.2)
rmagick (2.12.2)
ruby-debug-base (0.10.3)
ruby-debug-ide (0.4.5)
rubygems-update (1.3.7, 1.3.5, 1.3.3)
rvm (1.1.1)
sqlite3-ruby (1.3.2, 1.2.4)
test-spec (0.10.0)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.23)
yard (0.5.8)

My Mysql is up and running:

Macintosh:$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.53 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

This is all I have in my brand new application, but I'm still getting the missing mysql2 gem problem.

I have Snow Leopard 10.6.5 with X Code 3.2.4 installed.

Any idea?

Thanks in advance!


Source: (StackOverflow)

Cannot install mysql2 gem

I'm unable to install the mysql2 gem in my Windows7 x64 system. I tried using both the 32-bit and 64-bit versions of MySQL server but none got me any further.

I installed Ruby 1.8, the development kit and and the Rails platform. I even installed minGW to allow C++/C compilation of things. MySQL Server was installed in the default location.

When running the command:

C:\Users\Arne>gem install mysql2 -- --with-mysql-include="C:\Program Files (x86)\MySQL\MySQL Server 5.1\include" --with-mysql-lib="C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\"

I receive the following output from the console:

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

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=C:/Ruby/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include=${mysql-dir}/include
        --with-mysql-lib=${mysql-dir}/lib
        --with-libmysqllib
        --without-libmysqllib
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

        C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x
86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL
\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no


Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2 f
or inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2/ext/mysql2/gem_mak
e.out

The output of my environment according to Rubygems is:

C:\Users\Arne>gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.7.2
  - RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
  - EXECUTABLE DIRECTORY: C:/Ruby/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mingw32
  - GEM PATHS:
     - C:/Ruby/lib/ruby/gems/1.8
     - C:/Users/Arne/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

The following gems have been installed on the system as well:

C:\Users\Arne>gem list --local

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.7)
actionpack (3.0.7)
activemodel (3.0.7)
activerecord (3.0.7)
activeresource (3.0.7)
activesupport (3.0.7)
arel (2.0.9)
builder (3.0.0, 2.1.2)
bundler (1.0.12)
erubis (2.7.0, 2.6.6)
fastthread (1.0.7)
i18n (0.5.0)
mail (2.3.0, 2.2.18)
mime-types (1.16)
mysql (2.8.1 x86-mingw32)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.7.2, 0.6.14)
rack-test (0.5.7)
rails (3.0.7)
railties (3.0.7)
rake (0.8.7)
rdoc (3.5.3, 2.5.11)
rdoc-data (2.5.3)
rubygems-update (1.7.2)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27, 0.3.26)

I don't know what's missing or wrong, but the output files pointed to by the script contain the following data:

mkmf.log:

have_func: checking for rb_thread_blocking_region()... -------------------- no

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I.    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -L.      -lmsvcrt-ruby18-static  -lshell32 -lws2_32  "
conftest.c: In function 't':
conftest.c:7:53: error: 'rb_thread_blocking_region' undeclared (first use in this function)
conftest.c:7:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4: 
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))rb_thread_blocking_region; return 0; }
/* end */

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I.    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -L.      -lmsvcrt-ruby18-static  -lshell32 -lws2_32  "
C:\Users\Arne\AppData\Local\Temp\ccCicaNu.o: In function `t':
C:\Ruby\lib\ruby\gems\1.8\gems\mysql2-0.3.2\ext\mysql2/conftest.c:3: undefined reference to `rb_thread_blocking_region'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { rb_thread_blocking_region(); return 0; }
/* end */

--------------------

have_library: checking for main() in -llibmysql... -------------------- no

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -LC:\Program -L.      -lmsvcrt-ruby18-static -llibmysql  -lshell32 -lws2_32  "
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4: 
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */

"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program    -g -O2 -DFD_SETSIZE=256    conftest.c  -L. -LC:/Ruby/lib -LC:\Program -L.      -lmsvcrt-ruby18-static -llibmysql  -lshell32 -lws2_32  "
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { main(); return 0; }
/* end */

--------------------

gem_make.out:

C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no

I hope someone can point what I'm doing wrong, or what is actually missing on my development system to get this gem properly installed and working.


Source: (StackOverflow)

Undefined method `accept' for nil:NilClass on rake db:migrate

Using ruby-1.9.2 and rails 3.2.1. The version of mysql2 is 0.2.7.

Upon running rake db:migrate I get the error: "undefined method `accept' for nil:NilClass:"

Trace includes:

gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'


Source: (StackOverflow)

MySQL2 gem won't install

I have been trying to install Gitlab on my Ubuntu 12.04 server for a long time, and all goes well until I run bundle install.

It says it is unable to install MySQL2 but gives no reason or corrective action.

home/gitlab/gitlab$ sudo -u gitlab -H bundle install --deployment --without development test postgres
Fetching gem metadata from http://rubygems.org/.......
Fetching gem metadata from http://rubygems.org/..
Using rake (10.0.1) 
Using i18n (0.6.1) 
Using multi_json (1.3.7) 
Using activesupport (3.2.9) 
Using builder (3.0.4) 
Using activemodel (3.2.9) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.1) 
Using actionpack (3.2.9) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.9) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.9) 
Using activeresource (3.2.9) 
Using bundler (1.2.3) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.9) 
Using rails (3.2.9) 
Using acts-as-taggable-on (2.3.3) 
Using backports (2.6.5) 
Using bcrypt-ruby (3.0.1) 
Using blankslate (3.1.2) 
Using sass (3.2.3) 
Using bootstrap-sass (2.2.1.1) 
Using carrierwave (0.7.1) 
Using charlock_holmes (0.6.9) 
Using chosen-rails (0.9.8) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using coffee-rails (3.2.2) 
Using colored (1.2) 
Using daemons (1.1.9) 
Using orm_adapter (0.4.0) 
Using warden (1.2.1) 
Using devise (2.1.2) 
Using diff-lcs (1.1.3) 
Using draper (0.18.0) 
Using escape_utils (0.2.4) 
Using eventmachine (1.0.0) 
Using multipart-post (1.1.5) 
Using faraday (0.8.4) 
Using ffaker (1.15.0) 
Using sass-rails (3.2.5) 
Using font-awesome-sass-rails (2.0.0.0) 
Using foreman (0.60.2) 
Using gemoji (1.2.1) 
Using git (1.2.5) 
Using posix-spawn (0.3.6) 
Using yajl-ruby (1.1.0) 
Using pygments.rb (0.3.2) from https://github.com/gitlabhq/pygments.rb.git (at master) 
Using github-linguist (2.3.4) 
Using github-markup (0.7.4) 
Using gitlab_meta (4.0) 
Using gratr19 (0.4.4.1) 
Using grit (2.5.0) from https://github.com/gitlabhq/grit.git (at 7f35cb9) 
Using hashery (1.5.0) 
Using gitolite (1.1.0) 
Using grack (1.0.0) from https://github.com/gitlabhq/grack.git (at ba46f3b) 
Using hashie (1.2.0) 
Using multi_xml (0.5.1) 
Using rack-accept (0.4.5) 
Using rack-mount (0.8.3) 
Using virtus (0.5.2) 
Using grape (0.2.2) 
Using grit_ext (0.6.1) from https://github.com/gitlabhq/grit_ext.git (at 8e6afc2) 
Using haml (3.1.7) 
Using haml-rails (0.3.5) 
Using httparty (0.9.0) 
Using httpauth (0.2.0) 
Using jquery-atwho-rails (0.1.7) 
Using jquery-rails (2.1.3) 
Using jquery-ui-rails (2.0.2) 
Using jwt (0.1.5) 
Using kaminari (0.14.1) 
Using kgio (2.7.4) 
Using libv8 (3.3.10.4) 
Using modernizr (2.6.2) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
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... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

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/local/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11 for inspection.
Results logged to /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
root@Server:/home/gitlab/gitlab$

Source: (StackOverflow)

Ruby gem mysql2 install failing

When I try to install the mysql2 gem, it fails with no apparent errors. Does anyone know what to do to work around this so mysql2 installs? I am installing this on OS X.

Tanner-Smiths-MacBook-Pro:Humans_vs_Zombies_Parse tanner$ sudo gem install mysql2Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
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
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out


Source: (StackOverflow)

rails server fails to start with mysql2 using rvm & ruby 1.9.2-p0 on OSX 10.6.5

I'm getting the following error when I start rails server:

$ rails server
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require':     dlopen(/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError) 
Referenced from: /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2- 0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-    
0.2.6/lib/mysql2/mysql2.bundle

I've installed mysql2 with the following command after the rvm use ruby-1.9.2-p0 command:

$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known

I have mysql2 in my Gemfile as well as in the database.yml file and bundle install completes fine

$ bundle show mysql2
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6

I understand the rails server error is due to it not knowing the mysql_config location on OSX, however on gem install I specified the correct location. Yet RVM's gem is not respecting that mysql_config location it seems.

Anyone have a solution to this?


Source: (StackOverflow)

Ruby MYSQL2 gem installation on windows 7

I'm trying to installing the mysql2 gem on windows 7 I downloaded the connector from the mysql site and placed the libmysql.dll in ruby200\bin

then do gem install mysql2

These are the results am I being dim here?

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

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=C:/Ruby200/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/
extconf.rb:37:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError
)


Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.
3.13 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/ext/mysql2/g
em_make.out

Source: (StackOverflow)

Mysql 5.6 headaches on Mac OSX

Several of my colleagues and I have recently upgraded from MySQL 5.5 to MySQL 5.6 using homebrew on our Macs to test locally before upgrading our servers. Since this upgrade, we all have been experiencing intermittent MySQL errors when running our rails code:

Lost connection to MySQL server at 'sending authentication information', system error: 32

We have tried re-making our usernames and passwords in our database, and upping the connection timeout, but neither have fixed the problem. The error logs do not mention the issue. The only workaround we have found when we run into the problem is to kill mysql and restart it. I have even noticed this error more recently using mysql -u root -p on the command line. It seems that once I start getting this error, I cannot exceed my current number of connections no matter what username I use. If I close a connection, then I can re-open one.

We have the following environments:

  • some of us: Rails 3.2, Ruby 2, mysql2 0.3.13, MySQL 5.6.12, Mac OSX 10.8.4
  • others of us: Rails 3.2, Ruby 1.9, mysql2 0.3.13, MySQL 5.6.10, Mac OSX 10.8.4

Any ideas what might be causing this?

Thanks! Julie


Source: (StackOverflow)

Unable to install mysql2 gem on windows 7

I am getting the following error message while installing, let me know if any one needs some more details. I followed instruction from "https://github.com/oneclick/rubyinstaller/wiki/Development-Kit".

I am using ruby 1.9.2p136 (2010-12-25) [i386-mingw32].

E:\work_desk\trunk>gem install mysql2 -v 0.2.4
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

C:/Ruby192/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

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=C:/Ruby192/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-libmysqllib
        --without-libmysqllib


Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.
2.4 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.4/ext/mysql2/ge
m_make.out

Source: (StackOverflow)

mysql2 gem fails to compile with MySQL 5.6.12 on OS X with Homebrew

I updated all the packages I installed with Homebrew. MySQL got upgraded to 5.6.12 (from 5.5.27 or so):

$ mysql --version
mysql  Ver 14.14 Distrib 5.6.12, for osx10.8 (x86_64) using  EditLine wrapper

and now the mysql2 gem doesn't compile anymore:

$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

        /Users/pupeno/.rvm/rubies/ruby-1.9.3-p429-perf/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-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=/Users/pupeno/.rvm/rubies/ruby-1.9.3-p429-perf/bin/ruby
    --with-mysql-config
    --without-mysql-config

The file mysql.h is present in /usr/local/Cellar/mysql/5.6.12/include/mysql.h. Any ideas what's going on?

The file mysql.h doesn't appear in /usr/local because the symlink seems to go deeper than it should:

$ ls -la /usr/local/include/mysql
lrwxr-xr-x  1 pupeno  admin  36 21 Jun 15:18 /usr/local/include/mysql@ -> ../Cellar/mysql/5.6.12/include/mysql

instead of

/usr/local/Cellar/mysql/5.6.12/include

Having said that, I manually fixed the symlink and the compilation still failed. So I'm stuck.


Source: (StackOverflow)

rescuing from Mysql2::Error

I have a simple question. I have a join table which has an index that ensure that (col 1, col 2) is unique.

I am adding to that table using mysql2 gem and am trying to catch the Mysql2::Error if the attempt results in a duplicate key error. While I am getting the duplicate key error, my rescue body is not being executed.

begin
  self.foo << bar
rescue Mysql2::Error
  logger.debug("#{$!}")
end

I am receiving the following error upon executing self.foo << bar

Mysql2::Error: Duplicate entry '35455-6628' for key 'index_foos_bars_on_foo_id_and_bar_id': INSERT INTO foos_bars (foo_id, bar_id) VALUES (35455, 6628)

BUT my rescue statement is not being hit! The exception is not be successfully rescued from. What am I doing wrong? If I remove Mysql2::Error and rescue for everything, then it works. But that is bad practice - I just want to rescue from Mysql2::Error which in the event of a duplicate entry.

Thanks,


Source: (StackOverflow)