Rails rake db:create not working - mysql

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

Related

Rails aborted when put command 'rails db:schema:dump'

When I run rails db:schema:dump I receive this error
rails aborted!
LoadError: libmysqlclient.so.20: cannot open shared object file: No such file or directory - /home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/mysql2-0.4.5/lib/mysql2/mysql2.so
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/mysql2-0.4.5/lib/mysql2.rb:31:in `require'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/mysql2-0.4.5/lib/mysql2.rb:31:in `<top (required)>'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/runtime.rb:91:in `require'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/runtime.rb:86:in `each'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/runtime.rb:86:in `block in require'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/runtime.rb:75:in `each'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler/runtime.rb:75:in `require'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/bundler-1.14.3/lib/bundler.rb:107:in `require'
/home/mekjaaganu/Sites/simple_cms/config/application.rb:7:in `<top (required)>'
/home/mekjaaganu/Sites/simple_cms/Rakefile:4:in `require_relative'
/home/mekjaaganu/Sites/simple_cms/Rakefile:4:in `<top (required)>'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
/home/mekjaaganu/Sites/simple_cms/bin/rails:9:in `require'
/home/mekjaaganu/Sites/simple_cms/bin/rails:9:in `<top (required)>'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
/home/mekjaaganu/.rvm/gems/ruby-2.3.3/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
/home/mekjaaganu/Sites/simple_cms/bin/spring:15:in `require'
/home/mekjaaganu/Sites/simple_cms/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
My config/database.yml file looks like this. Already checked the database name and user password. Everything looks fine. Able to create database name simple_cms_development and password is right.
# MySQL. Versions 5.0 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: rails_user
password: secretpassword
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: simple_cms_development
# 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:
<<: *default
database: simple_cms_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass#localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: simple_cms_production
username: simple_cms
password: <%= ENV['SIMPLE_CMS_DATABASE_PASSWORD'] %>
You might be missing development libraries in your machine. Install this library if you dont already have it.
sudo apt-get install libmysqlclient20-dev

Mac OSX Rails Can not run Rake Command

I am trying to run rake command to build the db for my project. but i am encoutering the following error.
Harshas-MacBook-Pro:noise harshamv$ rake db:create
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"noise_development", "pool"=>5, "username"=>"hmv", "password"=>2206, "socket"=>"/var/run/mysqld/mysqld.sock"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"noise_test", "pool"=>5, "username"=>"root", "password"=>"root", "socket"=>"/var/run/mysqld/mysqld.sock"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
Rake db:migrate
Harshas-MacBook-Pro:noise harshamv$ rake db:migrate
rake aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `connect'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `initialize'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:863:in `initialize'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `new'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/Users/harshamv/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/Users/harshamv/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
But i am able to get connected into mysql from the CLI.
This is my Rails Configuration File
development:
adapter: mysql2
encoding: utf8
database: noise_development
pool: 5
username: hmv
password: *******
socket: /var/run/mysqld/mysqld.sock

WEBrick rails server (Psych::SyntaxError) | lynda.com tutorial

I'm a total newbie with RoR, so please forgive my density on this topic.
I'm trying to start the WEBrick application server using the rails server command, but I get the following error when I run it in my app directory /Users/Grace/Sites/simple_cms
I'm running the following:
Rails 3.2.13
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]
OSX 10.8.3
Here's the error stack:
Grace$ rails server
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://localhost:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): could not find expected ':' while scanning a simple key at line 18 column 3 (Psych::SyntaxError)
from /Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
from /Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:153:in `parse'
from /Users/Grace/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:129:in `load'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/application/configuration.rb:115:in `database_configuration'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:78:in `block (2 levels) in <class:Railtie>'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/base.rb:720:in `<top (required)>'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in `block in <class:Railtie>'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/Grace/Sites/simple_cms/config/environment.rb:5:in `<top (required)>'
from /Users/Grace/Sites/simple_cms/config.ru:3:in `require'
from /Users/Grace/Sites/simple_cms/config.ru:3:in `block in <main>'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/Grace/Sites/simple_cms/config.ru:in `new'
from /Users/Grace/Sites/simple_cms/config.ru:in `<main>'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/Grace/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
When I open up the psych.rb file I see this:
require 'psych.so'
require 'psych/nodes'
require 'psych/streaming'
require 'psych/visitors'
require 'psych/handler'
require 'psych/tree_builder'
require 'psych/parser'
require 'psych/omap'
require 'psych/set'
require 'psych/coder'
require 'psych/core_ext'
require 'psych/deprecated'
require 'psych/stream'
require 'psych/json/tree_builder'
require 'psych/json/stream'
require 'psych/handlers/document_stream'
###
# = Overview
#
# Psych is a YAML parser and emitter.
# Psych leverages libyaml [Home page: http://pyyaml.org/wiki/LibYAML]
# or [Git repo: https://github.com/zerotao/libyaml] for its YAML parsing
Please help! Thank you :)
Go into the database.yml file in your new rails project (if this is Lynda.com, that means it's the simple_cms project).
Make sure the keys on the left are followed by a colon, then a space, like this:
password: secret_phrase
And not like this, with no space after the colon:
password:secret_phrase
I also had the same problem and even though the indentations and spacings were correct in the database.yml I was still getting the errors. In my case the indentations were incorrect in the corresponding lines in application.yml.
Very good #Steel, but remove the space does not solve (increases the number of errors). But really this error indicates that the problem is in the database.yml.
In my case I had two statements socket.
Indentation of the code is important.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: xxx
pool: 5
username: xxx
password: xxx
socket: /socket_adress
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: xxx
pool: 5
username: xxx
password: xxx
socket: /socket_adress
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: xxx
pool: 5
username: xxx
password: xxx
socket: /socket_adress

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 ?