Rails 4.2.2 – Erreur d’installation de mysql2

Dans l’environnement de rails 4.2.2, j’essaie d’exécuter une bundle install pour un exemple de projet, mais je reçois une erreur comme ci-dessous

Gem :: Ext :: BuildError: ERREUR: Impossible de construire l’extension native gem.

 /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 est,

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

J’ai essayé d’installer mysql2 puis il a été installé mysql2 (0.4.0) mais cela montre l’erreur ci-dessous lors du démarrage d’un rails server

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

Comment résoudre le mysql2 installation de mysql2 ?

Il y a un bogue dans la version de mysql2-0.4.0 , examinez la question du voisin

Essayez d’installer la dernière version de mysql2-0.3.x :

Changer dans votre Gemfile:

  gem 'mysql2', '~> 0.3.13' 

Et courir

 bundle update mysql2 

Assurez-vous d’arrêter le spring via la spring stop , puis démarrez les rails.

Il y avait un problème dans mysql2 0.4.0 et les versions ultérieures.

 1) gem list mysql2 1. mysql2-0.3.20 2. mysql2-0.4.3 3. All versions 2)gem uninstall mysql2 3)Now change Gemfile gem mysql2,'0.3.14' 4)bundle