0

我试图将我的 ruby​​ 脚本连接到位于此处的本地 mysql 数据库:

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

我已经安装了这些宝石,其中 ruby​​ /Users/AM/.rvm/rubies/ruby-2.0.0-p247/bin/ruby

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

当我运行这个脚本时:

 #!/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

我收到此错误:

 /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>'

我究竟做错了什么?如何成功连接到 MySQL DB?

谢谢

4

1 回答 1

1

看起来您没有正确编译该 gem 的 C 扩展部分。它需要链接到mysql动态库。

重装试试?

于 2013-09-19T20:10:52.393 回答