安装mysql2 gem错误

时间:2011-04-24 22:35:18

标签: ruby-on-rails ruby ruby-on-rails-3 rubygems

我通过macport安装了ruby和ruby gem,但是gem列表中没有包含mysql2。那么如何在我的宝石列表中安装mysql2 gem,它位于“/ opt / local / bin / gem”里面

另外,mysql2的宝石是什么?我有mysql gem而且只想使用mysql,不太确定mysql2是什么意思。当我尝试在应用程序上启动webrick时,它会出现mysql2错误。

更新: 我运行了sudo gem install mysql2并获得了以下内容:

  

构建原生扩展。这个   可能需要一段时间......成功   安装mysql2-0.2.7 1安装宝石   安装ri文档   mysql2-0.2.7 ...

     

包含类/模块'mMysql2'   class客户端未知

     

包含类/模块'mMysql2'   class结果未知安装RDoc   mysql2-0.2.7的文档......

     

包含类/模块'mMysql2'   class客户端未知

     

包含类/模块'mMysql2'   class结果未知

假设安装了mysql2,即使文档没有,当我尝试在我的应用程序中启动webrick时,我收到以下错误。

rails server:

  

/opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle:   dlopen的(/opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle,   9):未加载库:   libmysqlclient.18.dylib(LoadError)
  参考自:   /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle   原因:图片未找到 -   /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle     从   /opt/local/lib/ruby/gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8     从   /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in   require' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in 需要'来自   /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in   each' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in 需要'来自   /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in   each' from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in 需要'来自   /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in   require' from /Users/summer/Sites/simple_cms/config/application.rb:7 from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:28:in 需要'来自   /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:28     从   /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:27:in   tap' from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:27 from script/rails:6:in需要”     来自script / rails:6

2 个答案:

答案 0 :(得分:2)

要搜索可用的远程gem,请运行该命令 gem search mysql2 -r(注意最后的-r)

*远程宝石*

activerecord-mysql2legacydb-adapter(0.2.0) activerecord-mysql2spatial-adapter(0.3.2) em_mysql2_connection_pool(0.0.5) ghazel-mysql2(0.2.6.3) mysql2(0.2.7,0.2.6 x86-mingw32 x86-mswin32-60) mysql2_bigint(0.2.6.1) mysql2_model(0.1.2) mysql2mysql(0.0.2) mysql2psql(0.1.0) mysql2xxxx(0.0.4)

从宝石列表中你应该选择mysql2并运行 sudo gem install mysql2

答案 1 :(得分:2)

据我所知,两个宝石(mysql和mysql2)之间的区别之一是mysql2在UTF-8上效果更好。关于它is an article

要安装mysql2 gem,只需运行:

gem install 'mysql2'