[英]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上学习课程,其步骤如下:
I installed Ruby + DevKit 2.4.4-1(x64) 我安装了Ruby + DevKit 2.4.4-1(x64)
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
I installed MySQL version 5.7.21 我安装了MySQL版本5.7.21
I installed mysql2 gem as follows gem install mysql2
我安装了mysql2 gem如下
gem install mysql2
I installed Atom text editor 我安装了Atom文本编辑器
I created a new project rails new kudaweb -d mysql
我创建了一个新项目
rails new kudaweb -d mysql
I created the required databases in the MySQL shell 我在MySQL Shell中创建了所需的数据库
CREATE DATABASE kudaweb_development;
and CREATE DATABASE kudaweb_test;
和
CREATE DATABASE kudaweb_test;
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'
,我也对测试数据库进行了此操作
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
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
0.4.9
or 0.4.10
gem 0.4.9
或0.4.10
宝石 set your gemfile to: 将您的gemfile设置为:
# ./Gemfile
...
gem 'mysql2', '0.4.9'
...
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.