rake aborted! uninitialized constant Mysql2 - mysql

Goksel-Eryigits-Mac-mini:blog geryit$ rake db:migrate --trace
(in /Users/geryit/Sites/blog)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Client does not support authentication protocol requested by server; consider upgrading MySQL client
/Users/geryit/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/mysql.rb:453:in `read'
/Users/geryit/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/mysql.rb:130:in `real_connect'
/Users/geryit/.rvm/gems/ruby-1.8.7-p330/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:600:in `connect'
/Users/geryit/.rvm/gems/ruby-1.8.7-p330/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:164:in `initialize
.
.
.
database.yml
development:
adapter: mysql
encoding: utf8
database: test
pool: 5
username: root
password:
socket: /tmp/mysql.sock

Have you defined
gem 'mysql2'
in Gemfile? For Rails 3 and Bundler, it's not enough to install the gem, but to include it in Gemfile.

They work together now without any problems. The problem was Mysql version and mysql gem flags. I removed MYSQL 5.5 and installed Mysql 5.1 back. Everything is fixed. Thanks.
I wrote a blog post about installing, it can be helpful : https://geryit.com/blog/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

Try uninstalling the mysql gem. It might be conflicting with the mysql2 gem you're using in your database.yml.

I was getting 'uninitialized constant Mysql' on Snow Leopard and Rails 3. Adding 'mysql' gem to Gemfile fixed it for me.

Related

Ruby on rails "NameError: uninitialized constant Mysql2::Client::REMEMBER_OPTIONS"

I am trying to learn web development with ruby on rails. I have been following a course on Lynda.com and my steps were as follows:
I installed Ruby + DevKit 2.4.4-1(x64)
I installed rails as in the command line as follows
gem install rails --version 5.0.0
I installed MySQL version 5.7.21
I installed mysql2 gem as follows
gem install mysql2
I installed Atom text editor
I created a new project rails new kudaweb -d mysql
I created the required databases in the MySQL shell
CREATE DATABASE kudaweb_development; and CREATE DATABASE kudaweb_test;
I then created a new user and granted all privileges as follows
GRANT ALL PRIVILEGES ON kudaweb_development.* TO 'rails_user'#'localhost' IDENTIFIED BY 'mypassword'
and i did this for the test database as well
I configured the database.yml file as follows:
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: rails_user
password: mypassword
host: localhost
I ran the following code to check if I had correctly configured the database
rails db:schema:dump
and I got the following error
C:\Users\Dj K-Staxx\Desktop\RUBY\kudaweb>rails db:schema:dump
rails aborted!
NameError: uninitialized constant Mysql2::Client::REMEMBER_OPTIONS
bin/rails:4:inrequire'
bin/rails:4:in <main>'
Tasks: TOP => db:schema:dump
I have no idea how to resolve this. I have searched the internet for solutions but to no avail. I am using windows 7 64bit and for the mysql2 gem I am using version 0.5.0
Seems like there may be some config issue between your 0.5.0 gem and mysql. It may not have built correctly. see: https://github.com/brianmario/mysql2/issues/954
Option 1: try reverting to 0.4.9 or 0.4.10 gem
set your gemfile to:
# ./Gemfile
...
gem 'mysql2', '0.4.9'
...
Option 2: try to compile the gem locally with c-connector
You may need a local C-connector to properly build the gem locally. see: https://www.digitalgyan.org/how-to-install-ruby-on-rails-mysql2-gem-on-windows-10/
that may be as simple as downloading the appropriate files from MySQL: https://dev.mysql.com/downloads/connector/c/
In either scenario, you may benefit from a quick script to test out connection (to rule out Rails as the problem).
require 'mysql2'
client = Mysql2::Client.new(host: "localhost", username: "rails_user", password: "mypassword")
update mysql2 gem in the Gemfile as:
gem 'mysql2', '~> 0.5.2'

RoR 4 ERROR on 'rake db:create' or 'rake about'

I have RoR 4.0 and ruby-1.9.3-p484 installed. gem install bundler and bundle install run without any errors. Then I need to create a db using rake db:create and I'm getting following error (I get the same error on rake about as well):
rake aborted! Could not load
'active_record/connection_adapters/mysql2_adapter'. Make sure that the
adapter in config/database.yml is valid. If you use an adapter other
than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary
adapter gem to the Gemfile.
From gem list:
activerecord-mysql2-adapter (0.0.3)
mysql2 (0.3.14)
rake (10.1.1, 0.9.2.2)
config/database.yml
adapter: mysql2
encoding: utf8
host: localhost
database: my_database
pool: 20
username: root
password:
socket: /tmp/mysql.sock
MySQL is running
Please let me know if I should share some more informaion. Thank you!!!
Thank you everybody for your suggestions! I finally found the solution.
Apparently, mysql2 gem did not work well with mysql-5.5.12. It was also installed from source files on my mac. I deleted mysql from my machine and installed it using Brew following steps here. Everything seems fine now.

Heroku installing Amazon RDS : mysql or mysql2?

I'm installed the Amazon RDS Add-on in Heroku, and created OK an instance in Amazon AWS. But I can't run
heroku run rake db:migrate
It's ending with
(...)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
undefined method `accept' for nil:NilClass
/app/vendor/bundle/ruby/1.9.1/gems/activerecord- 3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:38:in `select_values'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:587:in `get_all_versions'
When I created my instance I followed the instructions from Heroku :
$ heroku addons:add amazon_rds url=mysql2://user:pass#rdshostname.amazonaws.com/databasename
And since then, I'm fighting with Mysql2. First I noticed in Heroku that it was pointing to
mysql://user:pass#mydatabase.us-east-1.rds.amazonaws.com/MyFirstDb
Is it normal that there is no 2 like mysql2://user ? I added it. I changed my Gemfile with
gem 'mysql2', '< 0.3.7'
and my database.yml with
production:
adapter: mysql2
database: db/production.mysql2
before it was set as sqlite3.
I'm newbie, this is my first app that I want to deploy to Amazon AWS so maybe I miss something obvious ! Any idea ?
I got it ! I had forgotten to
gem install activerecord-mysql2-adapter
The error message in Heroku says to run gem install activerecord-mysql-adapter (without the 2), but with the 2, it works perfectly now !
I hope this post will help others. So, to sum up, here is what you need to do :
1- Set the "2" in the add-on link in Heroku
mysql2://user:pass#mydatabase.us-east-1.rds.amazonaws.com/MyFirstDb
2- Add a line to your Gemfile :
gem 'mysql2', '~> 0.3.11'
3- Change your database.yml
production:
adapter: mysql2
database: db/production.mysql2
4- Run
gem install activerecord-mysql2
heroku run rake db:migrate
And enjoy ! :-)

Rails 3.1 rc4 problem with mysql2

I just installed passenger (apache2) on my ubuntu server to deploy my rails 3.1 rc4 rails app into the wild, and wanted to change from sqlite to mysql.
I installed the necessary ubuntu packages
I updated my Gemfile with the recommended:
gem 'mysql2'
And updated my database.yml file
production:
adapter: mysql2
database: database
username: deploy
password: (***blocked for security reasons***)
socket: /var/run/mysqld/mysqld.sock
pool: 5
timeout: 5000
When I try to create the production database with rake:
rake db:migrate RAILS_ENV=”production” --trace
It gives me a bunch of crazy errors
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
”production” database is not configured
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord- 3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/railtie.rb:69:in `block (2 levels) in <class:Railtie>'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
(And so on)
I have tried install the regular mysql gem, which also didn't work. I have also tried <0.3 of mysql2, but that seemed to lead to an error being thrown complaining about using versions 0.2 with rails 3.1 rc4
I am really stumped :/
have you tried without the quotes around "production" ?
RAILS_ENV=production rake db:migrate

Rails : rake db:create mysql error

I am trying to setup a mysql database, but I am getting this error message:
rake db:create
(in /Users/yookd/Desktop/rails/blog)
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Blog::Application#task called at /Library/Ruby/Gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
db/test.sqlite3 already exists
rake aborted!
uninitialized constant Mysql2
Tasks: TOP => db:create
(See full trace by running task with --trace)
Any assistance with this?
(following directions on http://guides.rubyonrails.org/getting_started.html)
EDIT:::
How can I use mysql as my database as opposed to sqlite? In the gemfile, it explicitly states: gem 'sqlite'... do I need to replace that line with something like gem mysql?
This is a known issue. See: Rails - rake db:create error
BUT note that Rake 0.9.1 has been released which supposedly fixes things. So first try upgrading rake with:
gem update rake
And update your bundle:
bundle update rake
For your edit, yes, to use mysql you have to first have mysql installed and configured on your system. Then in your gemfile, remove 'gem sqlite' and replace it with:
gem 'mysql'
Then, in your config/database.yml, set it up something similar to:
development:
adapter: mysql
database: name_of_database
pool: 5
timeout: 5000
host: localhost
password: mysql_password
Do the same for test and production.