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

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'

Related

RoR database Error

Trying to run the database in RoR i have this error
Couldn't create database for {"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
but when i do gem list i get that i have mysql2 (0.4.1)
How can i fix this? and also, why does this happens?
Check /config/database.yml file
Probably your file contains something like this:
development:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/development.sqlite3
Change sqlite to mysql and add login settings, also check environment (development, production or test)
you need to run bundle install as you have already added the gem in the Gemflle.Also you need to setup mysql and other libs before installing it.
You should include the mysql2 gem into your gemfile and run 'bundle install'.
Also your config/database.yml should look something like the below
development:
adapter: mysql2
encoding: utf8
database: my_db_name
username: root
password: my_password
Here the username and password will be the one you gave at the time of configuring the mysql inyour system

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.

Getting mysql gem working with ruby-1.9.3 on rvm

I am trying to setup mysql gem on ruby-1.9.3 installed with rvm. I want to set up the 'redmine'. To install mysql gem I used -->
sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/bin/mysql_config
When I issue --> RAILS_ENV=production rake db:migrate, I get
/Users/myth/.rvm/gems/ruby-1.9.3-p0#global/gems/bundler-1.1.2/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
cannot load such file -- mysql
However I have successfully deployed redmine1.3 on default ruby1.8.7 installation of OSX with installing mysql gem the very same way.
I want to work on the latest trunk with ruby-1.9.3
How can I resolve the issue? I have been searching the mailing list and found similar posts, however could not solve the problem.
I also struggled with this question. I could not get redmine working with mysql and ruby 1.9.3.
The answer is very easy and simple. For ruby 1.9.3 together with redmine you have to use the gem mysql2 !
In http://www.redmine.org/projects/redmine/wiki/RedmineUpgrade#Option-1-Downloaded-release-targz-or-zip-file it is also written to change the database adapter from mysql to mysql2.
So install gem install mysql2 and also keep sure to have a
database.yml with msql2 adapter:
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: redmine
encoding: utf8

Rails mysql2 error: "rake aborted! Please install the mysql2 adapter..."

I am running this on a Windows 7 (64 bit) machine. I installed RoR using the one-click installer. I've updated my database.yml file to use mysql2:
development:
adapter: mysql2
encoding: utf8
database: blog_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
database: blog_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
database: blog_production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
I added this line to my Gemfile (per the tutorial video):
gem 'mysql2', :group => :production
Then:
gem install mysql2
which succeeds. Then:
bundle install
Which also succeeds, but mysql2 is not listed.
Then:
rake db:create
which gives this error:
"rake aborted!
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (my
sql2 is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:create
(See full trace by running task with --trace)"
bundle show mysql2
Gives this error: "Could not find gem 'mysql2' in the current bundle."
What am I missing to get mysql2 going?
Run bundle install before rake db:create (after the gem install mysql2)
Go to your app
Open Gemfile
Add this line
gem 'mysql2'
Similar issue was resolved for me after
creation of libmysql.lib file per https://github.com/brianmario/mysql2/issues/486 and using it to install/compile native gems (lib resided in directory used for "--with-mysql-lib="$mysql top_path/lib"" gem installation)
putting libmysql.dll to ruby_top bin folder
installing both mysql and mysql2 gems (was getting exactly the same error with just mysql2 gem installed, though database.yml had "adapter = mysql2" everywhere).
After all that mysql2 appeared in list of gems after command "bundle install", I was able to run "rake db:create" successfully, started redmine x64 windows on x64 ruby 2.0 with x64 mysql on webrick, going on with configuring on some production server.
===============
An update
I have to precise that besides installing both mysql and mysql2 I created file Gemfile.local in redmine application top directory which probably made the trick with bundler.
So I would recommend to replace the last step with:
installing mysql2 gem
creating the file Gemfile.local in application top directory where
you list local gems to be included to your bundle.
I saw another answer that recommends to add mysql2 gem to Gemfile, but for me mysql2 was already included in Gemfile but has appeared in bundler output after adding to Gemfile.local only.
I'm leaving both solutions if I'm wrong and the trick was done by mysql gem installed together with mysql2, unfortunatelly I cannot remove/reinstall all from scratch now to test that for sure, I will update when I'm able to do so, hope all this will save some time to someone.
My Gemfile.local file contents is:
---8<---
gem "mysql2", "~> 0.3.11"
gem "eventmachine"
gem "thin"
---8<---

How do I change my database from SQLite to MYSQL in Rails

I know that you have to change the database.yml but I don't know what to change it to and how to download MYSQL and all of that jazz.
Gemfile:
gem 'mysql2'
config/database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: db_name_here
pool: 5
username: root
password:
host: localhost
Command line:
bundle install
rake db:create
rake db:migrate
Of course MySQL needs to be installed.
If you're creating a new project:
rails new app_name_here -d mysql
I ran into the same problem when trying to use the mysql2 gem with Rails 3.0.9.
When I ran rake db:create after installing the mysql2 gem, it gave me these warnings:
WARNING: This version of mysql2 (0.3.6) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
To specify that you only want to use the 0.2.x versions of mysql2, edit your Gemfile so that
gem 'mysql2'
becomes
gem 'mysql2', '~> 0.2.1'
As of Rails 6 a command has been added to do this automatically.
$ rails db:system:change --to=mysql
conflict config/database.yml
Overwrite /home/jim/Rails projects/myapp/config/database.yml? (enter "h" for help) [Ynaqdhm] y
force config/database.yml
gsub Gemfile
gsub Gemfile
Ref.: https://www.bigbinary.com/blog/rails-6-has-added-a-way-to-change-the-database-of-the-app