Reputation: 1986
I am attempting to follow this Redmine setup tutorial. When I get to the point of starting the server, I type sudo rails server
and I get the following error:
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it to Gemfile.) (LoadError)
The relevent section of my Gemfile reads:
....
if File.exist?(database_file)
database_config = YAML::load(ERB.new(IO.read(database_file)).result)
adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
if adapters.any?
adapters.each do |adapter|
case adapter
when /mysql/
gem "mysql", "~> 2.8.1", :platforms => [:mri_18, :mingw_18]
gem "mysql2", "~> 0.3.11", :platforms => [:mri_19, :mingw_19]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
...
and Gemfile.lock contains mysql2:
...
multi_json (1.5.0)
mysql (2.8.1)
mysql2 (0.3.11)
net-ldap (0.3.1)
...
and my database.yml file includes the following:
...
production:
adapter: mysql2
database: redmine
host: localhost
username: ****
password: ****
development:
adapter: mysql2
database: redmine_development
host: localhost
username: ****
password: ****
encoding: utf8
...
Running bundle install
seems to succeed, but mysql2 is not listed in the output, which mysql2
returns nothing, and bundle show mysql2
returns Could not find gem 'mysql2' in the current bundle.
I have uninstalled and reinstalled the mysql2 gem, with apparent success each time.
I have read through descriptions of similar-sounding problems on other stackoverflow questions, but none of their solutions turned out to solve my problem.
Upvotes: 2
Views: 4411
Reputation: 11904
You will get this error if mysql2
is not included in the Gemfile.lock
file that's generated by bundle
. While the Gemfile is used to manage dependencies, the lock file is what is actually loaded by the rails app.
That's a more verbose Gemfile than I have seen before (I'm not generally familiar with Redmine)- where is this from? It doesn't appear to be from the most recent stable source. If you know you'll be using mysql2, I don't think there's any reason you need your Gemfile to parse your database config. For whatever reason, it's not properly reading the database.yml file.
Try adding gem 'mysql2'
outside any blocks or loops and run bundle
again.
Upvotes: 2