Search code examples
mysqlruby-on-railsrubymysql2

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:

  1. I installed Ruby + DevKit 2.4.4-1(x64)

  2. I installed rails as in the command line as follows gem install rails --version 5.0.0

  3. I installed MySQL version 5.7.21

  4. I installed mysql2 gem as follows gem install mysql2

  5. I installed Atom text editor

  6. I created a new project rails new kudaweb -d mysql

  7. I created the required databases in the MySQL shell

CREATE DATABASE kudaweb_development; and CREATE DATABASE kudaweb_test;

  1. 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

  1. I configured the database.yml file as follows:

    default: &default adapter: mysql2 encoding: utf8 pool: 5 username: rails_user password: mypassword host: localhost

  2. 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


Solution

  • 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")