In rails 4.2.2 environment, I am trying to run bundle install for one sample project but I am getting an error like below
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/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 is,
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'
I have try to install mysql2 then it got installed mysql2 (0.4.0) but this will shows below error while starting a 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)
How can I solve mysql2 installation issue?
There's a bug in mysql2-0.4.0 version, look into neighbor question
Try to install latest mysql2-0.3.x version:
Change in your Gemfile:
gem 'mysql2', '~> 0.3.13'
And run
bundle update mysql2
Make sure to stop spring via spring stop and then start rails.
Related
I have been getting this Error when trying to do anything after starting the server in Rails:
Puma caught this error: Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? mysql2 is not part of the bundle. Add it to your Gemfile. (LoadError)
.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.2.7/lib/bundler/rubygems_integration.rb:334:in `block (2 levels) in replace_gem'
.....
However I am not using mysql adapter in the database.yml file, I have installed rails app with default database settings.
Does it have something to do with the previous application I was working on, we were using docker and mysql2 there.
Gemfile:
ruby '2.6.5'
gem 'rails', '~> 6.0.3', '>= 6.0.3.4'
gem 'sqlite3', '~> 1.4'
gem 'puma', '~> 4.1'
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
I had DATABASE_URL env variable set as mysql2 for the last application I was working on, so when i created the new App, rails set my default database to that, further info on the link below.
Found answer here.
So I'm running rspec tests with jruby-1.7.16.1 after completing a bundle install, and they are all failing to the same error:
Failure/Error: Unable to find arjdbc/jdbc/RubyJdbcConnection.java to read failed line
ActiveRecord::JDBCError:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
# arjdbc/jdbc/RubyJdbcConnection.java:453:in `init_connection'
Occasionally I would get an error like this when I'd forget to start mysql server, but I ensured it was running.
The GemFile is as such
source 'http://rubygems.org'
gem 'rails', '3.2.8'
gem 'rubyzip', '0.9.9'
gem 'roo','1.12.1'
gem 'jdbc-mysql', '5.1.33', platform: :jruby
gem 'activerecord-jdbcmysql-adapter', '1.3.12', platform: :jruby
gem 'jquery-rails', '2.1.2'
gem 'haml', '3.1.7'
gem 'puma', '2.9.2'
gem 'devise', '2.1.2'
gem 'devise-async', '0.5.0'
gem 'cancan', '1.6.8'
gem 'simple_form', '2.0.4'
gem 'cocoon', '1.1.1'
gem 'inherited_resources', '1.3.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.9'
gem 'mechanize', '2.5.1'
gem 'delayed_job', '3.0.4'
gem 'paperclip', '3.4.0'
gem 'spreadsheet', '0.6.4.1'
gem 'geocoder', '1.1.6'
gem 'whenever', '0.8.2'
gem 'american_date', '1.0.0'
gem 'money','5.1.1'
gem 'rets', '0.11.0'
gem 'haversine','0.3.0'
gem 'celluloid','0.15.2'
gem 'sinatra', '1.4.6'
source "https://9789474f:e71b0546#gems.contribsys.com/" do
gem 'sidekiq-pro','1.9.2'
end
gem 'redis','3.2.1'
gem 'remote_lock','1.1.0'
gem 'sidekiq-limit_fetch','2.3.0'
group :assets do
gem 'stylus', '0.7.1'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.3.0'
end
group :development do
gem 'net-ssh', '2.9.4'
gem 'capistrano', '3.4.1'
gem 'capistrano-rails', '1.3.0'
gem 'capistrano-rvm', '0.1.2'
end
group :development, :test do
gem 'dotenv-rails', '2.2.1'
gem 'rspec-rails', '~> 3.5'
gem 'fantaskspec'
end
group :test do
gem 'factory_girl_rails', '~> 4.0'
gem 'fantaskspec'
gem 'vcr'
gem 'fakeweb'
end
gem 'rest-client', '1.8.0'
gem 'poltergeist', '1.8.1'
gem 'nokogiri', '1.5.11'
gem 'zip-codes', '0.2.1'
gem 'elasticsearch-model', '0.1.9'
gem 'elasticsearch-rails', '0.1.9'
gem "fog", '1.38.0'
gem 'newrelic_rpm', '3.18.1.330'
gem 'sidekiq-scheduler', '2.1.7'
gem 'aws-sdk', '2.10.28'
gem 'StreetAddress', '1.0.6'
If there is more information required I'd be happy to provide it, let me know if anyone has run into this.
The odd thing is, these spec tests used to work fine prior to a merge I did with our repository. The other dev doesn't seem to be running into this same issue, so I can only assume the Gemfiles are all correct and that my environment is the issue.
Make sure the database is up and running.
Does the user that's trying to connect to the database has permission to connect? Try logging in with that user in the client software.
Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server
Try creating a new user with admin privileges and try connecting.
Advice: Try using a software that keeps your development environments in sync, and test it well. We use Vagrant to reproduce development environments.
When I try to run the following code in Rails using Mysql2 as database manager:
rake db:migrate
I obtain the following error:
rake aborted!
"Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL:"
Why do I get this error, if the primary key in a table by default is NOT "null"?
Migration code, however :
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string "first_name"
t.timestamps
end
end
end
I had a same problem before, and I solved according to here
https://github.com/rails/rails/pull/13247#issuecomment-32425844
With Rails 2.3.5, MySQL version 5.7.9 and mysql gem you need to have
this bit as an initializer in
config/initializers/abstract_mysql_adapter.rb:
class ActiveRecord::ConnectionAdapters::MysqlAdapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end
For mysql2, it should be config/initializers/abstract_mysql2_adapter.rb:
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end
From the mysql 5.7 breaking change page:
Columns in a PRIMARY KEY must be NOT NULL, but if declared explicitly
as NULL produced no error. Now an error occurs. For example, a
statement such as CREATE TABLE t (i INT NULL PRIMARY KEY) is rejected.
The same occurs for similar ALTER TABLE statements. (Bug #13995622,
Bug #66987, Bug #15967545, Bug #16545198)
Changes in MySQL 5.7.3 (2013-12-03, Milestone 13)
This issue was fixed 3 months ago. I don't know what Rails version it's going to be part of
monkey patch is here
EDIT:
It's been more than a year that this fix was merged into master. So, it must be part of the last version of Rails.
EDIT:
Indeed, the commit that fixes this can be found at: https://github.com/yahonda/rails/commit/b6655885ef13cf8d1705dc9b5232846f0207febd , and shows that the fix is included in v4.2.0.beta1, v4.1.6.rc1, v4.1.5, v4.1.4, v4.1.3, v4.1.2, v4.1.2.rc3, v4.1.2.rc2, v4.1.2.rc1, v4.1.1, v4.1.0, v4.1.0.rc2, v4.1.0.rc1, v4.1.0.beta2, v4.1.0.beta1. If upgrading to at least v4.1.0 is an option for you, then it should fix the problem.
I had this issue running a rails 4.0.x app using mysql 5.7.x. I was able to fix it by upgrading to rails 4.2.x and upgrading my gems.
(I'm sure these gemfiles need work, but hopefully they are still helpful)
Old Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.13'
gem 'mysql2'
# Use unicorn as the app server
# gem 'unicorn'
gem 'sidekiq'
gem 'sinatra'
gem 'whenever'
gem 'thin'
gem 'faye'
gem 'faye-websocket'
#pdf generation
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
# Assets
gem 'backbone-on-rails', '~> 0.9.9'
gem 'coffee-rails', '~> 4.0.1'
gem 'coffee-script-source', '=1.8.0'
gem 'ejs' # uses templates for backbone
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'neat'
gem 'sass-rails', '~> 4.0.3'
gem 'therubyracer'
gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'
gem 'active_model_serializers', '0.8.3'
gem 'acts_as_list'
gem 'bcrypt-ruby', '~> 3.1.2'
gem 'bootstrap-sass', '~> 3.2.0.0'
gem 'bower-rails'
gem 'carrierwave'
gem 'enumerize'
gem 'embedly' # Url to Attachment Processing
gem 'fancybox2-rails', '~> 0.2.4'
gem 'flamegraph'
gem 'fog' # s3 storage
gem 'globalize' # I18n for tagging, etc.
gem 'globalize-accessors'
gem 'i18n-tasks', '~> 0.8.3'
gem 'hirb'
gem 'kaminari'
gem 'nokogiri'
gem 'newrelic_rpm'
gem 'select2-rails' # Token Fields
gem 'twilio-ruby'
gem 'rails_autolink' # Convert urls to links
gem 'redis', '3.2.1'
gem 'rest-client'
gem 'rmagick'
gem 'rubyzip', :require => 'zip' # Zip files together
gem 'unf'
gem 'mailgun-ruby', '~>1.0.3', require: 'mailgun'
# Deployments
gem 'mina'
group :doc do
gem 'sdoc'
end
group :test do
gem 'rspec-rails', "= 2.14.2"
gem 'shoulda-matchers', :require => false
gem 'simplecov', '~> 0.9.2'
gem 'database_cleaner'
gem 'codeclimate-test-reporter', require: nil
end
group :development, :test do
gem 'quiet_assets'
gem 'factory_girl_rails', "~> 4.0"
gem 'guard', '>=2.1.0'
gem 'guard-rspec', '= 4.2.9'
gem 'spring', '1.3.6'
gem 'spring-commands-rspec'
gem 'foreman'
end
New Gemfile
source 'https://rubygems.org'
ruby '2.3.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
gem 'mysql2'
gem 'stackprof'
# Use unicorn as the app server
# gem 'unicorn'
gem 'sidekiq'
gem 'sinatra'
gem 'whenever'
gem 'thin'
gem 'faye'
gem 'faye-websocket'
#pdf generation
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
# Assets
gem 'backbone-on-rails', '~> 0.9.9'
gem 'coffee-rails', '~> 4.0.1'
gem 'coffee-script-source', '=1.8.0'
gem 'ejs' # uses templates for backbone
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'neat'
gem 'sass-rails', '~> 4.0.3'
gem 'therubyracer'
gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'
gem 'active_model_serializers', '0.8.3'
gem 'acts_as_list'
gem 'bcrypt', '~> 3.1.2'
gem 'bootstrap-sass', '~> 3.2.0.0'
gem 'bower-rails'
gem 'carrierwave'
gem 'enumerize'
gem 'embedly' # Url to Attachment Processing
gem 'fancybox2-rails', '~> 0.2.4'
gem 'flamegraph'
gem 'fog' # s3 storage
gem 'globalize' # I18n for tagging, etc.
gem 'globalize-accessors'
gem 'i18n-tasks', '~> 0.8.3'
gem 'hirb'
gem 'kaminari'
gem 'nokogiri'
gem 'newrelic_rpm'
gem 'select2-rails' # Token Fields
gem 'twilio-ruby'
gem 'rails_autolink' # Convert urls to links
gem 'redis', '3.2.1'
gem 'rest-client'
gem 'rmagick'
gem 'rubyzip', :require => 'zip' # Zip files together
gem 'unf'
gem 'mailgun-ruby', '~>1.0.3', require: 'mailgun'
gem 'rack-cors', :require => 'rack/cors'
# Deployments
gem 'mina'
group :doc do
gem 'sdoc'
end
group :test do
gem 'rspec-rails', "= 2.14.2"
gem 'shoulda-matchers', :require => false
gem 'simplecov', '~> 0.9.2'
gem 'database_cleaner'
gem 'codeclimate-test-reporter', require: nil
end
group :development, :test do
gem 'quiet_assets'
gem 'factory_girl_rails', "~> 4.0"
gem 'guard', '>=2.1.0'
gem 'guard-rspec', '= 4.2.9'
gem 'spring', '1.6.1'
gem 'spring-commands-rspec'
gem 'foreman'
end
I have a old rails project that is using rails 3.0.9 and I am trying to run it using rails s. It appears that when I do this is gives me the following error:
You will see that it says that the current adapter that I have installed is not supported by foriegner. I have updated my gemfile to look like the following:
gem 'rake', '0.9.2.2'
gem 'mysql2'
gem 'rails', '3.0.9'
gem "acl9"
gem 'foreigner'
gem 'devise'
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails'
gem 'lazy_high_charts'
gem 'client_side_validations'
gem 'carrierwave'
gem 'tiny_mce'
#gem 'devise_security_extension'
#gem 'rails_email_validator'
#gem 'easy_captcha'
group :development do
gem 'rspec-rails', '2.6.1'
gem 'jspec'
gem 'faker', '0.3.1'
gem 'rspec'
gem 'annotate'
end
group :test do
gem 'rspec-rails', '2.6.1'
gem 'spork', '0.9.0.rc8'
gem 'webrat'
gem 'autotest-growl'
gem 'autotest-rails'
gem 'autotest', '4.4.6'
gem 'autotest-rails-pure', '4.1.2'
gem 'factory_girl_rails'
gem 'ZenTest'
gem 'test-unit'
end
What I don't seem to understand is why it would say in the command prompt that the gem is missing and I need to add it to my gemfile when it is there. What is the best solution to tackling this.
It isnt working cause you are trying to install the latest version of mysql2 which doesnt work with rails 3.0.X. You can get around this by specifying the version this way
gem 'mysql2', '< 0.3' or gem "mysql2", "~> 0.2.7"
But to get around the foreigner dependency which is probably the main issue here:
You can upgrade your rails version to 3.1.x or higher and upgrade the mysql2 in the gem file. I see that you have a recent version of ruby.
After you update the gems in the gemfile, make sure you run bundle install in the command line...before trying to start the server. Also, ensure that you setup your database in the database.yml file in the config folder.
edit your config/database.yml file from:
adapter: mysql
to
adapter: mysql2
i have git clone git://github.com/jalagrange/excel_test_app.git
I got the below error while the bundle install, This does not happen with other my applications.
following error
Installing mysql2 (0.3.6) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem "spreadsheet"
gem "carrierwave"
gem "mini_magick"
gem 'flash_cookie_session'
gem "pry"
gem "haml"
gem 'fog'
# To use Delayed_job
gem 'daemons'
gem 'delayed_job_active_record'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
group :development, :test do
gem "mysql2", "0.3.6"
gem "letter_opener"
gem "pry"
end
this question and answer not working for my problem..
gem install: Failed to build gem native extension (can't find header files)
problem solved,
i have run bundle update..
thx all..
Run the following command and install the bundle again
sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo apt-get install libmysqlclient-dev
then
gem install mysql2 -v=X.X.x
where x.x.x is the version that you need
then bundle install
2018.11.05 => Depreciated.
After an apt search libmysqlclient-dev you will get the new package you will need to continue installing mysql2.
In my case it results default-libmysqlclient-dev
apt install default-libmysqlclient-dev
gem install mysql2 -v 0.4.6
=> then you can restart thebundle installenter code here cmd.