Question

Im trying to connect my ruby script to the local mysql database located here:

  which mysql
  /usr/local/mysql/bin/mysql

Ive got these gems installed which ruby /Users/AM/.rvm/rubies/ruby-2.0.0-p247/bin/ruby

 gem list
 ......
 mysql2 (0.3.13)
 ......

When I run this script:

 #!/usr/bin/env ruby 
 require 'mysql2'

 begin
     client = Mysql2::Client.new(:host => 'localhost', :database => '0828FromSQL', :username => "root", :password => "")

 rescue Mysql2::Error => e
     puts e.errno
     puts e.error 
 ensure
     con.close if con
 end

I get this error:

 /Users/AM/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
 from /Users/AM/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
 from /Users/AM/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `<top (required)>'
 from /Users/AM/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:116:in `require'
 from /Users/AM/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:116:in `rescue in require'
 from /Users/AM/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:122:in `require'
 from mysqltester.rb:3:in `<main>'

WHat am I doing wrong? How can I connect to the MySQL DB successfully?

Thanks

Was it helpful?

Solution

It looks like you haven't compiled the C extension part of that gem properly. It needs to link to the mysql dynamic library.

Try reinstalling it?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top