mysql - Rails 4.2.2 - mysql2 安装错误

标签 mysql ruby-on-rails ruby ubuntu

在 rails 4.2.2 环境中,我尝试为一个示例项目运行 bundle install 但我收到如下错误

Gem::Ext::BuildError:错误:无法构建 gem native 扩展。

/home/aparna/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150912- 2709-1b70inv.rb extconf.rb 
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling mysql2_ext.c
In file included from ./client.h:11:0,
             from ./mysql2_ext.h:39,
             from mysql2_ext.c:1:
/home/aparna/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/backward/rubysig.h:14:2: warning: #warning rubysig.h is obsolete [-Wcpp]
#warning rubysig.h is obsolete
^
In file included from ./mysql2_ext.h:39:0,
             from mysql2_ext.c:1:
./client.h: In function ‘rb_thread_blocking_region’:
./client.h:23:3: error: ‘TRAP_BEG’ undeclared (first use in this function)
TRAP_BEG;
^
./client.h:23:3: note: each undeclared identifier is reported only once for each function it appears in
./client.h:25:3: error: ‘TRAP_END’ undeclared (first use in this function)
TRAP_END;
^
mysql2_ext.c: At top level:
./client.h:16:1: warning: ‘rb_thread_blocking_region’ defined but not used [-Wunused-function]
rb_thread_blocking_region(
^
make: *** [mysql2_ext.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/aparna/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.13 for inspection.
Results logged to /home/aparna/.rvm/gems/ruby-2.2.1/extensions/x86_64-linux/2.2.0/mysql2-0.3.13/gem_make.out
An error occurred while installing mysql2 (0.3.13), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.13'` succeeds before bundling.

Gemfile 是,

source 'https://rubygems.org'

gem 'rails', '4.2.0'
gem 'mysql2', '0.3.13'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'therubyracer', platforms: :ruby

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
 gem 'byebug'
 gem 'web-console', '~> 2.0'
 gem 'spring'
end

gem 'protected_attributes'

gem 'devise'

gem 'paperclip'
gem "cocaine"

gem "simple_form"

gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"

gem 'kristin'
gem 'docsplit'
gem 'pdf2html'

我尝试安装 mysql2 然后它安装了 mysql2 (0.4.0) 但是这将在启动 rails 服务器

时显示以下错误
/home/aparna/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

如何解决 mysql2 安装问题?

最佳答案

mysql2-0.4.0 版本有bug,查看neighbor question

尝试安装最新的mysql2-0.3.x版本:

更改您的 Gemfile:

 gem 'mysql2', '~> 0.3.13'

然后运行

bundle update mysql2

确保通过spring stop停止spring,然后启动rails。

关于mysql - Rails 4.2.2 - mysql2 安装错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32537786/

相关文章:

php - 如何从mysql表中获取数组的单个值并在搜索中使用

ruby-on-rails - 我是否需要在我的 Rails 应用程序中关闭与 Amazon S3 的连接?

ruby-on-rails - 我应该使用 `respond_to` 还是在 Rails 中有一个专用的 API 命名空间?

ruby - 在 jruby 线程设置中使用 redis

mysql - 复制mysql数据库导入时生成 "ERROR: unknown command"

php - 如何使用 php 使用数据库信息动态更新页面

ruby-on-rails - Rails - 简单形式 - bool 属性不接受错误/无单选按钮选择

ruby-on-rails - 如何从我的网站在 Facebook 上发布新闻源

ruby - 允许返回的 block 使用大括号

.net - MySQL .Net 连接器 - SELECT 始终返回 0 行