How to connect mysql2 to Ruby on Rails? - mysql

I am trying to work on a RoR project, I have created the project called tester to check my db connection, command which I had used is 'rails new tester -d mysql'
my gemfile has mysql2 gem included
I have installed mysql and workbench, and my database.yml looks like this:
default: &default
adapter: mysql2
encoding: utf8
pool: <%=ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password: password
host: localhost
socket: MySQL
development: <<: *default
database: tester_development
test: <<:*default
database: tester_test
production: <<: *default
database: tester_production
username: tester
password: <%=ENV['TESTER_DATABASE_PASSWORD'] %>
And my cmd error is following:
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load such file -- mysql2/2.4/mysql2 (LoadError)
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9-x64-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9-x64-mingw32/lib/mysql2.rb:31:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:81:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:76:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:76:in `block in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:65:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:65:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler.rb:114:in `require'
from C:/Users/donki/Desktop/testing/tester/config/application.rb:7:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:133:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:133:in `block in perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Sorry for the long post. I really do not understand what the error is. The error occurs when I try to run rails server.
Help would be appreciated.

It's seems like you are using windows and ruby 2.4
but I think mysql2 library not support ruby 2.4 in windows till now,
So, It would be better to use ruby 2.3 instead of ruby2.4
Hope it will help you.
reference

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

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

Rails server fails to boot with mysql2 - Gems it requires, exists

This is me trying to use MySql on rails for the first time. This happens with using sqlite3 as well except it points to me do 'gem install activerecord-sqlite3-adapter`,the tells me there is no such gem named it.
I am using the lastest Ruby 2.0.
I am using the lastest Rails 3.2.13
I have the mysql2 (0.3.11) gem
I also have the activerecord-mysql2-adapter (0.0.3)
Yet... it is giving me the following message:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in 'block in replace_gem': Please install the mysql2 adapter: 'gem install activerecord-mysql2-adapter' (mysql2 is not part of the bundle. Add it to Gemfile.) (LoadError)
The bundler ran when I executed rails new [project name]
If it was mysql2 gem's error, this command successfully installs mysql2 on 64 bit Windows systems:gem install mysql2 -v '0.3.11' -- '--with-mysql-lib="C:\MySQL\lib" --with-mysql-include="C:\MySQL\include"'
Gemfile generated is using gem 'mysql2'ok, normal as I have been told.
Database.yml is as follows:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: shop_development
pool: 5
username: charlie
password: *******
host: localhost
And I have manually created a database called [projectname]_development.
C:\Users\Charlie\Documents\RailsProject\demo_app>rails s
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integ
ration.rb:214:in `block in replace_gem': Please install the mysql2 adapter: `gem
install activerecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it
to Gemfile.) (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/dependencies.rb:251:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/dependencies.rb:251:in `block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/dependencies.rb:236:in `load_dependency'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/dependencies.rb:251:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/connection_adapters/abstract/connection_specification.rb:50:in `resol
ve_hash_connection'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/connection_adapters/abstract/connection_specification.rb:41:in `resol
ve_string_connection'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/connection_adapters/abstract/connection_specification.rb:130:in `esta
blish_connection'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/lazy_load_hooks.rb:36:in `instance_eval'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/lazy_load_hooks.rb:36:in `execute_hook'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/lazy_load_hooks.rb:42:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/ac
tive_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/base.rb:720:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/act
ive_record/railtie.rb:88:in `block in <class:Railtie>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/i
nitializable.rb:30:in `instance_exec'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/i
nitializable.rb:30:in `run'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/i
nitializable.rb:55:in `block in run_initializers'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/i
nitializable.rb:54:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/i
nitializable.rb:54:in `run_initializers'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/a
pplication.rb:136:in `initialize!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/r
ailtie/configurable.rb:30:in `method_missing'
from C:/Users/Charlie/Documents/RailsProject/demo_app/config/environment
.rb:5:in `<top (required)>'
from C:/Users/Charlie/Documents/RailsProject/demo_app/config.ru:3:in `re
quire'
from C:/Users/Charlie/Documents/RailsProject/demo_app/config.ru:3:in `bl
ock in <main>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder
.rb:51:in `instance_eval'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder
.rb:51:in `initialize'
from C:/Users/Charlie/Documents/RailsProject/demo_app/config.ru:in `new'
from C:/Users/Charlie/Documents/RailsProject/demo_app/config.ru:in `<mai
n>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder
.rb:40:in `eval'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder
.rb:40:in `parse_file'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/server.
rb:200:in `app'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/c
ommands/server.rb:46:in `app'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/server.
rb:304:in `wrapped_app'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/server.
rb:254:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/c
ommands/server.rb:70:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/c
ommands.rb:55:in `block in <top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/c
ommands.rb:50:in `tap'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/c
ommands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Check for following things
Does your Gemfile have the entry saying gem 'mysql2' ?
What happens when you run $ bundle update command? any errors
Can you try the following command to generate your app,
rails new demo_app -d mysql
What error you get when you try the above app?

Connect existing MySQL database in rails

I want to connect my Ruby on Rails application with a MySQL database, which was developed separately. For this connection I used the
development environment:
adapter: mysql
username: root
password: ******
host: 127.0.0.1
port: 3306
When I try to make the MySQL connection in Rails it shows:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `require': Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.9. (RuntimeError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
from D:/registration/config/application.rb:7:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:53:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:53:in `block in <top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
D:\registration>
Also, when I try my rake command it shows:
rake aborted!
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.9.
D:/registration/config/application.rb:7:in `<top (required)>'
D:/registration/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
D:\registration>
How can I connect to my database?
As per the error it seems like you are using a newer version of the gem than your MySQL client.
It says:
Your gem has been compiled (created with) my sql client version 6.0.0.
Your actual my sql client version (in your machine) is 5.5.9.
Could you post your MySQL gem version as well as your MySQL client version?
Upgrating your MySQL client to version 6.0.0 should fix this issue.

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 ?