rails 5 mysql adapter issue - mysql

Am trying to create a model in rails 5 and have installed mysql-community-server. Also I have installed both mysql and mysql2 gem's. But when i run rails generate model Book getting below error,
[root#server-linux library]# rails generate model Book
/root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require': Could not load 'active_record/connection_adapters/mysql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0/lib/active_record/connection_handling.rb:53:in `establish_connection'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0/lib/active_record/railtie.rb:125:in `block (2 levels) in <class:Railtie>'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0/lib/active_record/base.rb:324:in `<module:ActiveRecord>'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0/lib/active_record/base.rb:24:in `<top (required)>'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:338:in `active_record_configured?'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:259:in `disconnect_database'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:97:in `preload'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:143:in `serve'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
from /root/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /root/.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /root/.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
[root#server-linux library]#
database.yaml:
[root#server-linux library]# cat config/database.yml
development:
adapter: mysql2
database: library_development
username: root
password: [password]
host: localhost
test:
adapter: mysql2
database: library_test
username: root
password: [password]
host: localhost
production:
adapter: mysql2
database: library_production
username: root
password: [password]
host: localhost
[root#server-linux library]#
Version details:
[root#server-linux library]# rails -v
Rails 5.0.0
[root#karthick-linux library]# gem list | grep mysql
activerecord-mysql-adapter (0.0.1)
mysql (2.9.1)
mysql2 (0.4.4)
[root#server-linux library]#
Even I created application with the command rails new library -d mysql
Any idea why its failing with mysql adapter connection.

Did you try installing bundler. I am guessing that mysql2 gem is installed for different version of ruby and not your current version of ruby. Try installing bundler first.
gem install bundler
bundle install
rails db:migrate
rails g model book
Also you won't need mysql gem, you can just delete it and use mysql2 as adapter in your database.yml file.

Check your Gem file
in your gem file find gem 'mysql2'
if not found please add gem 'mysql2' then run bundle install and restart server.

Related

mysql2 gem is not compatible with mysql 5.6.19 [duplicate]

This question already has answers here:
mysql2 gem compiled for wrong mysql client library
(8 answers)
Closed 8 years ago.
I want to run a rails application on my mac osx 10.9.3 and got following error:
/Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `require': Incorrect MySQL client library version! This gem was compiled for 5.5.23 but the client library is 5.6.19. (RuntimeError)
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in `require'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in `each'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in `block in require'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in `each'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in `require'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler.rb:132:in `require'
from /Users/home/workSpace/RubyOnRails/simple_cms/config/application.rb:7:in `<top (required)>'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `require'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `block in server'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
I installed mysql with hombrew and it's working perfectly. I also use rbenv.
gem 'rails', '4.1.1'
gem 'mysql2'
and this is my databas.yml file
development:
adapter: mysql2
encoding: utf8
database: simple_cms_development
pool: 5
username: root
password: somepassword
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
database: simple_cms_test
pool: 5
username: root
password: somepassword
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
database: simple_cms_production
pool: 5
username: root
password: somepassword
socket: /tmp/mysql.sock
How can I solve it?
Headers
I was going to suggest using mysql C-connector (the recommended answer in the comments confirmed this)
We've written a tutorial on how to do this (for the typical unable to build native extensions error), but same idea
--
C-Connector
Basically, your gem just needs to interface with your system; it doesn't need need to do anything buy send queries & process the responses to your db
This means if you have a problem with your mysql version's compatibility, you'll be best installing & using a separate batch of header files (for your gem):
The way to do this is to download & install the mysql c-connector
files - IMPORTANT - GET THE 32 BIT VERSION (you can either use
the installer or unzip the files)
Once installed, you should install the gem with the following command:
gem install mysql2 --platform=ruby -- ‘--with-mysql-dir="YOUR_MYSQL_DIR”’
This should install the gem for you, which will allow you to interface with the MYSQL server

JRuby on Rails rake db: tasks all abort with jdbc mysql

we are trying to integrate an existing mysql database in our jruby on rails application.
Our client provided us with a bare bone rails skeleton, which was not configured for a sepcific database. We were later provided with a sql database and were asked to integerate it in our application using mysql. We started out by creating a database.yml file with the necessairy information. We then executed the rake db:create command, which resulted in following error message below. Any suggestions on what we're doing wrong? We're helpless. Thx in advance.
$ rake db:create --trace
rake aborted!
undefined method `each' for nil:NilClass
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:15:in `redefine_task'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:23:in `(root)'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:22:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:234:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/default_loader.rb:6:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:569:in `load_imports'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:508:in `raw_load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/bin/rake:19:in `(root)'
our system specification:
Java SE 6
JRuby 1.6.6
Rails 3.1
we use following gems for our datebase:
gem 'mysql2', '~>0.3.0'
gem "jdbc-mysql", "~> 5.1.13"
gem "activerecord-jdbc-adapter", "~> 1.2.2"
gem "activerecord-jdbcmysql-adapter", "~> 1.2.2"
our database.yml file:
development:
database: webgrouper_development
adapter: jdbcmysql
encoding: utf8
reconnect: true
pool: 5
username: root
password:
host: 127.0.0.1
test:
database: webgrouper_test
adapter: jdbcmysql
encoding: utf8
reconnect: false
pool: 5
username: root
password:
host: 127.0.0.1
production:
database: webgrouper_production
adapter: jdbcmysql
encoding: utf8
reconnect: false
pool: 5
username: root
password:
host: 127.0.0.1
What I can say so far, having run across this while troubleshooting something else and happening to have the relevant source code up, is that this rake task is dying because it is attempting to iterate over the actions for the current task, but the set of actions is nil.
Understanding exactly what was done wrong in the terse and uncommented code in there is difficult. Something is making this incredibly fragile system break down. I have an odd wild guess. What happens if you put "adapter: jdbcmysql" as the first part of each database stanza in your YML, instead of "database: webgrouper_production"?

Rails 3.2.2 mysql2 adapter Error

I've been having trouble getting the mysql2 adapter working with the latest version of rails. I Just generated a new project. Added the following to my gemfile:
gem 'mysql2', '< 0.3.7'
then of course ran:
bundle install
I also modified my database.yml file:
development:
adapter: mysql2
encoding: utf8
database: blog_development
username: root
password: *********
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
database: blog_test
username: root
password: ********
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
database: blog_production
username: root
password: *********
socket: /tmp/mysql.sock
So when I try and run rake db:create, the following is the output.
$ rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.3.6. Make sure all dependencies are added to Gemfile.)
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:157:in `block in replace_gem'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:48:in `resolve_hash_connection'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:27:in `spec'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:67:in `create_database'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:40:in `block (3 levels) in <top (required)>'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:40:in `each'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:40:in `block (2 levels) in <top (required)>'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/teddyknox/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `load'
/Users/teddyknox/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `<main>'
Tasks: TOP => db:create
It's telling me to install:
gem install activerecord-mysql2-adapter
But this gem doesn't exist. I'm pretty confused. I've tried many different versions of mysql2 and none seem to work. Any ideas?
Using the following in the gemfile seemed to work:
gem "mysql2", "~> 0.3.11"
It looks like one of your gems requires mysql2 ~> 0.3.10 (meaning >= 0.3.10 && < 0.4), while you are requiring it < 0.3.7. Try removing the constraint on the version and bundle install again ?

Rails rake db:create not working

Hey everyone! I am having trouble setting up a MySQL database for my rails application. Here are the contents of my database.yml file:
development:
  adapter: mysql
  encoding: utf8
reconnect: false
  database: app_name_dev
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  encoding: utf8
reconnect: false
  database: app_name_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock
production:
  adapter: mysql
  encoding: utf8
reconnect: false
  database: app_name_pro
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock
I also replaced gem sqlite3 with gem mysql in my gemfile and ran bundle install. Now I am trying to create the database for the first time with rake db:create. I am getting the following error:
$ rake db:create --trace
(in c:/Users/Kvass/documents/programming/ruby/app_name)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
couldn't parse YAML at line 1 column 0
c:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse'
c:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
c:/Ruby192/lib/ruby/1.9.1/psych.rb:119:in `parse'
c:/Ruby192/lib/ruby/1.9.1/psych.rb:106:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application/configu
ration.rb:88:in `database_configuration'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/railtie
s/databases.rake:4:in `block (2 levels) in <top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in exec
ute'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invo
ke_with_call_chain'
c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_c
all_chain'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in `block in invo
ke_prerequisites'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prereq
uisites'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:in `block in invo
ke_with_call_chain'
c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_c
all_chain'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 lev
els) in top_level'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top
_level'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exc
eption_handling'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run
'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exc
eption_handling'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
c:/Ruby192/bin/rake:19:in `load'
c:/Ruby192/bin/rake:19:in `<main>'
Can someone please explain what I am doing wrong? Thanks!
The MySQL server had not been running on my machine when I tried to run rake db:create. Careless mistake :P
Try using this as your database.yml:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &TEST
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
cucumber:
<<: *TEST
In my development process i use this config:
development:
adapter: mysql2
database: my_db
encoding: utf8
username: rails
password: rails
host: localhost

rails mysql adapter error

I'm having trouble finding a solution to this problem. I'm getting the error
Please install the mysql adapter: 'gem install activerecord-mysql-adapter'
when I specify either ruby-mysql or mysql2 in my Gemfile. This has only happened since I've upgraded to Rails 3.1.0-rc1. I'm running OSX 10.6, Ruby 1.9.2.
cody$ rails c
/Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (RuntimeError)
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in `establish_connection'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/railtie.rb:69:in `block (2 levels) in <class:Railtie>'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/base.rb:2135:in `<top (required)>'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/railtie.rb:34:in `block in <class:Railtie>'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `call'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `block in load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `each'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/railtie.rb:177:in `load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application.rb:115:in `block in load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application/railties.rb:8:in `each'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application/railties.rb:8:in `all'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/application.rb:115:in `load_console'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:26:in `start'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start'
from /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is the gem env output
cody$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-darwin10.7.3]
- INSTALLATION DIRECTORY: /Users/cody/.rvm/gems/ruby-1.9.2-p180
- RUBY EXECUTABLE: /Users/cody/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
- EXECUTABLE DIRECTORY: /Users/cody/.rvm/gems/ruby-1.9.2-p180/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /Users/cody/.rvm/gems/ruby-1.9.2-p180
- /Users/cody/.rvm/gems/ruby-1.9.2-p180#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
You'll have to change your config/database.yml to use the mysql2 adapter instead of mysql.
So replace:
adapter: mysql
With:
adapter: mysql2
I had to enforce the use of mysql2 gem version 0.2.7 and while trying to upgrade my rails 3.0.7 app to 3.1.0.rc1, I also noticed ,that you'll need the following new gems in your Gemfile, too:
gem 'mysql2', '< 0.3' # as stated above
# Asset template engines
gem 'json'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
# other required things for rails 3.1
gem 'jquery-rails'
gem 'mustang' # this is ONE execjs backend of many, and the only one that worked for me.
Tell me if that worked for you.
Fixed the problem by updating the gemfile for my app to identify mysql2 as part of the bundle.
To do this, navigate to the root of your app, run open gemfile
Add the line gem 'mysql2', '< 0.3.7' directly below the gem line for rails.
While in terminal at the root of your app, run bundle install
Run bundle show mysql2 to verify the bundle worked. You should be good to go with the adapter now.
My environment is Rails 3.1, MySql 5.5, Ruby 1.9.2.
I created a Rails project on windows and moved it to a machine running Fedora. I solved this problem by renaming the "Gemfile.lock" to "old_Gemfile.lock". Of course, you must still specify the adapter as 'mysql2' and include the appropriate gem in your gemfile.