Ruby on rails: mysql error - mysql

I'm using windows xp 32 pro, bit, sp3. the latest version of railsinstaller, and mysql2 gem
i have been trying to solve this error all this week. When i run rake db:create I see this error
this is what i see when i trace the error
i have solved this error by downloading the zipped version of mysql Connector/C 6.0.2 for 32 bit and copying libmysql.dll from mysql-connector-c-noinstall-6.0.2-win32-vs2005\lib
to C:\RailsInstaller\Ruby1.9.2\bin
now when I run rake db:create i see
and this is what i see when i trace the error
i hope these info will help you, to help me solve the problem :)
#phoet
my gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'cucumber'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'capybara'
gem 'rspec', '2.8'
gem 'rspec-rails', '2.8'
gem 'launchy'
gem 'spork'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# 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
my db config
development:
adapter: mysql
database: selvista
username: root
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:
adapter: mysql
database: selvista_test
username: root
pool: 5
timeout: 5000
production:
adapter: mysql
database: selvista_prod
username: root
pool: 5
timeout: 5000
should my adapter be mysql2?

You can try to put mysql2 on your adapter lines in you database.yml.
development:
adapter: mysql2
database: selvista
username: root
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:
adapter: mysql2
database: selvista_test
username: root
pool: 5
timeout: 5000
production:
adapter: mysql2
database: selvista_prod
username: root
pool: 5
timeout: 5000

Related

LoadError: Error loading the 'mysql2' Active Record adapter [rails 5.2.3]

My rails app is using ruby 2.6.3, rails 5.2.3, and MySQL version is 5.7.27. When I tried to run rake db:create then rails showed me the error:
rails aborted!
LoadError: Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? cannot load such file -- /path/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb
bin/rails:4:in `<main>'
Caused by:
LoadError: cannot load such file -- /path/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb
bin/rails:4:in `<main>'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
this is my Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.2.3'
# Use mysql as the database for Active Record
gem 'mysql2', '0.5.2'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
# authentication
gem 'devise'
gem 'devise-i18n'
# admin
gem 'administrate'
gem 'haml-rails'
gem 'bootstrap'
gem 'jquery-rails'
group :development, :test do
gem 'rspec-rails'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'better_errors'
gem 'pry-byebug'
gem 'pry-rails'
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rubocop', require: false
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 chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
and this is my db configuration:
# MySQL. Versions 5.1.10 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:
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: name
password: password
host: localhost
port: 3306
development:
<<: *default
database: project_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: project_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: project_production
username: videomeeting
password: <%= ENV['PROJECT_DATABASE_PASSWORD'] %>
I also checked from the gem list and saw that mysql2 already installed. Do you have any suggestion with this error? Thanks in advance.
Fixed this issue by reinstall activerecord gem.
I had a similar problem with postgresql and doing "gem install pg" worked for me.
Had this issue a while back, uninstall the mysql gem via the
bundle exec gem uninstall mysql2
and uninstall MySQL on your PC via
brew uninstall mysql#5.7
Re-install both:
brew install mysql#5.7
gem install mysql2 -v '0.5.2'
and hopefully it'll work for you as it did for me. I still however had to figure out the appropriate configurations as you have here:
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: name
password: password
host: localhost
port: 3306
Because I wanted to connect my rails app to a MySQL running on Docker, I set my configurations to:
db_database: 'cs_development'
db_username: ''
db_password: 'MySQL'
db_host: '127.0.0.1'
db_port: '3306'
db_adapter: 'mysql2'

Rails server not starting on Port 3000 "TCPServer Error: Permission denied - bind (2)"

I installed Ruby on Rails, MySQL Server 5.6, and the mysql2 gem on my Windows 7 computer. MySQL Server 5.6 runs on port 3000. My database.yml file is:
# MySQL2
# gem install mysql2
# Ensure the mysql2 gem is defined in your Gemfile
# gem 'mysql2'
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1_development
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
# 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: mysql2
encoding: utf8
reconnect: false
database: demo1_test
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
I ran "bundle install" with the following Gemfile:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use mysql2 as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
gem 'devise'
gem 'protected_attributes'
gem 'terminator'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
I could run the "bundle install", "rake db:create" and "rake db:migrate" commands without any problems. I started the MySQL server and typed "rails s" in the command line. The result was the following:
WARN TCPServer Error: Permission denied - bind (2)
Exiting
I made sure to open port 3000 in Windows Firewall, and allow rails to communicate through the firewall.
Typing "rails s -p 80" works, and the web application works on localhost:80, but the fields won't work because MySQL Server will not run on port 80.
Am I missing something? How can I get the Rails server and web app to work?
It looks like you're trying to run both the database AND the rails web server on port 3000.
EDIT: To clarify, you should probably run the rails server at port 3000 (the default), and run mysql on a different port.
Whatever port you run mysql on, put that port in your database.yml settings under "port:".
I think you should be using port 3306? This is what my connection string looks like and it works fine.
staging:
adapter: mysql2
encoding: utf8
host: 10.0.0.16
database: my_database
port: 3306
username: my_username
password: my_password
Note that the port of your webserver and your database are two different things. I run my webserver normally on port 3000 and mysql on 3306. I think 3306 is the default port used for mysql.

What does collation mean in this particular error and what is the charset?

I am trying to make a rails 3.1 app using mysql, its my first time using it
I am getting an error when I try to rake db:create
The Error
Can't connect to local MySQL server through socket '/tmp/mysql.socket' (2) Couldnt create database for {database.yml info in here}
(if you set the charset manually, make sure you have a matching collation)
I was looking at this link http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard/ which was posted in this question here rake db:create - collation issues
but I dont think that applies, doesnt mysql get installed when i do install gem mysql 'gem-version'?
can someone please help me solve this error? I am also running osx 10.7
Thank you very much in advance!
This is what my gem file looks like
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem "mysql2"
gem "activerecord-mysql2-adapter"
gem 'pry'
gem 'pry-debugger'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'rspec-rails', '~> 2.0'
gem 'database_cleaner'
gem 'shoulda-matchers'
end
gem 'jquery-rails'
my database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: Training_development
pool: 5
username: root
password:
host: localhost
# 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: mysql2
encoding: utf8
reconnect: false
database: Training_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: Training_production
pool: 5
username: root
password:
host: localhost

Rails 3.2.3 wants sqlite3 gem on mysql production env

I have a Rails 3.2.3 application which gets deployed with Capistrano. Until now, this workflow worked perfectly for several months now. But since the last deployment of the latest changes, the rake db:migrate action hangs because it can't find the SQLite3 gem and adapter.
executing "cd /home/*/*/*/releases/20120425232058 && bundle exec rake RAILS_ENV=production db:migrate"
executing command
rake aborted!
Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.)
the thing is, the application is running on MySQL. I have in my Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'jquery-rails'
gem 'omniauth-openid'
gem 'will_paginate'
gem 'pusher'
gem 'carrierwave'
gem 'capistrano'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :production do
gem 'mysql2'
end
group :production do
gem 'unicorn'
end
and the database.yml file:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: *****_development
pool: 5
username: *****
password: *****
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: *****_production
pool: 5
username: *****
password: *****
host: localhost
the application runs without problems in production mode on my local machine.
why is Rails trying to install SQLite ?
I beleive you have sqlite specified in your config/database.yml
My bad guys. Something went wrong in the Capistrano recipe. Thanks though for your answers !
Can you post the list of changes in the new deployment? Perhaps it's an issue with one of the gems that also use ActiveRecord?

Cannot access mysql on ruby on rails

I am trying get my first simple project in rails to run. I have installed wamp. And trying to make use of that same mysql db server installed with wamp. But I decided to make use of webrick, and not apache. Hoping that the configuration would be easier.
I edited the database.yml file and the gemfile under my projects directory:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
# 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: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
production:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
And here's gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.5'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
I used the command gem install mysql because mysql2 doesn't work for me.
What I did was to launch wampserver and stopped the apache service. It would take forever to load:
http://localhost:3000/rails/info/properties
Then webrick would crash. But if I do not launch wamp, I get this:
Did you configure mysql to run on a port other than 3306? If you're using a different port than that, you'll need to edit as follows:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
port: 3306 #replace with the correct port
If that doesn't work, also try changing localhost to 127.0.0.1 in order to force it to use TCP. Sometimes it tries to use sockets and cannot find the socket file.