简体   繁体   English

Ruby on Rails“ NameError:未初始化的常量Mysql2 :: Client :: REMEMBER_OPTIONS”

[英]Ruby on rails “NameError: uninitialized constant Mysql2::Client::REMEMBER_OPTIONS”

I am trying to learn web development with ruby on rails. 我正在尝试使用ruby on rails学习Web开发。 I have been following a course on Lynda.com and my steps were as follows: 我一直在Lynda.com上学习课程,其步骤如下:

  1. I installed Ruby + DevKit 2.4.4-1(x64) 我安装了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 我在命令行中gem install rails --version 5.0.0 ,如下所示gem install rails --version 5.0.0

  3. I installed MySQL version 5.7.21 我安装了MySQL版本5.7.21

  4. I installed mysql2 gem as follows gem install mysql2 我安装了mysql2 gem如下gem install mysql2

  5. I installed Atom text editor 我安装了Atom文本编辑器

  6. I created a new project rails new kudaweb -d mysql 我创建了一个新项目rails new kudaweb -d mysql

  7. I created the required databases in the MySQL shell 我在MySQL Shell中创建了所需的数据库

CREATE DATABASE kudaweb_development; and CREATE DATABASE kudaweb_test; 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 GRANT ALL PRIVILEGES ON kudaweb_development.* TO 'rails_user'@'localhost' IDENTIFIED BY 'mypassword' ,我也对测试数据库进行了此操作

  1. I configured the database.yml file as follows: 我将database.yml文件配置如下:

    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:in C:\\Users\\Dj K-Staxx\\Desktop\\RUBY\\kudaweb>rails db:schema:dump rails aborted! NameError: uninitialized constant Mysql2::Client::REMEMBER_OPTIONS bin/rails:4:in require' bin/rails:4:in <main>' Tasks: TOP => db:schema:dump C:\\Users\\Dj K-Staxx\\Desktop\\RUBY\\kudaweb>rails db:schema:dump rails aborted! NameError: uninitialized constant Mysql2::Client::REMEMBER_OPTIONS bin/rails:4:in / 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 我正在使用Windows 7 64bit,对于mysql2 gem我正在使用版本0.5.0

Seems like there may be some config issue between your 0.5.0 gem and mysql. 似乎您的0.5.0 gem和mysql之间可能存在一些配置问题。 It may not have built correctly. 它可能没有正确构建。 see: https://github.com/brianmario/mysql2/issues/954 参见: https : //github.com/brianmario/mysql2/issues/954

Option 1: try reverting to 0.4.9 or 0.4.10 gem 选项1:尝试还原为0.4.90.4.10宝石

set your gemfile to: 将您的gemfile设置为:

# ./Gemfile
...
gem 'mysql2', '0.4.9'
...

Option 2: try to compile the gem locally with c-connector 选项2:尝试使用C连接器在本地编译gem

You may need a local C-connector to properly build the gem locally. 您可能需要本地C连接器才能在本地正确构建gem。 see: https://www.digitalgyan.org/how-to-install-ruby-on-rails-mysql2-gem-on-windows-10/ 参见: 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/ 就像从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). 在这两种情况下,您都可以受益于快速的脚本来测试连接(将Rails排除在问题之外)。

require 'mysql2'
client = Mysql2::Client.new(host: "localhost", username: "rails_user", password: "mypassword")

将Gemfile中的mysql2 gem更新为:

gem 'mysql2', '~> 0.5.2'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未初始化的常量Mysql2 :: Client :: SECURE_CONNECTION - uninitialized constant Mysql2::Client::SECURE_CONNECTION 耙子流产了!未初始化的常量Mysql2 - rake aborted! uninitialized constant Mysql2 Ruby on Rails:MySql Gem不起作用:未初始化的常量Mysql :: Error - Ruby on Rails: MySql Gem does not work: uninitialized constant Mysql::Error 将MySQL2与Ruby结合使用可获取main:Object(NameError)的未定义局部变量或方法“ client” - Using MySQL2 with Ruby gets me undefined local variable or method `client' for main:Object (NameError) Ruby on Rails中的Mysql2安装 - Mysql2 Installation in Ruby on Rails Mysql2::Error: # MySQL 客户端未连接 — Rails 6.0.2.2 with rspec; Ruby 2.6.4 mac os Catalina + Mojave - Mysql2::Error: # MySQL client is not connected — Rails 6.0.2.2 with rspec; Ruby 2.6.4 mac os Catalina + Mojave 连接到外部MySQL数据库时出现“ NameError:未初始化常量”错误 - "NameError: uninitialized constant' error when connecting to external MySQL database Rails:ActiveRecord类抛出“ NameError:未初始化的常量”-这是命名问题吗? - Rails: ActiveRecord class throws “NameError: uninitialized constant” - Is this a naming issue? Ruby on Rails:未初始化的常量MysqlCompat :: MysqlRes - Ruby on Rails: uninitialized constant MysqlCompat::MysqlRes Ruby on Rails捆绑安装mysql2错误 - Ruby on Rails bundle install mysql2 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM