[英]cannot load such file — mysql2/2.4/mysql2 (LoadError)
I am new to Ruby On Rails. 我是Ruby On Rails的新手。 I have been trying to create a model called Book using rails generate model Book command but I am getting the following error message: 我一直在尝试使用rails generate model Book命令创建一个名为Book的模型,但出现以下错误消息:
F:\Faizul\Noah-Data\Backup\Ruby\Rails App\library>rails generate model Book
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load such file -- mysql2/2.4/mysql2 (LoadError)
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
from F:/Faizul/Noah-Data/Backup/Ruby/Rails App/library/config/application.rb:7:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/actions.rb:15:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands/generate/generate_command.rb:19:in `perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Made the below actions to overcome the issue but failed though :( 采取以下措施克服了这个问题,但失败了:(
default: &default adapter: mysql2 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 development: adapter: mysql2 database: library_development username: root password: root host: localhost port: 3309 test: adapter: mysql2 database: library_test username: root password: root host: localhost port: 3309 production: adapter: mysql2 database: library_production username: root password: root host: localhost port: 3309
Currently, There is no mysql2 binary for Ruby 2.4 for Windows available at this time. 当前,目前没有适用于Windows的Ruby 2.4的mysql2二进制文件。
Please see this github issue for more info https://github.com/brianmario/mysql2/issues/861 请参阅此 github问题以获取更多信息https://github.com/brianmario/mysql2/issues/861
Hope this may help you. 希望这对您有帮助。
compile your mysql comment worked for me https://github.com/brianmario/mysql2/issues/923#issuecomment-361346864 编译您的mysql注释对我有用https://github.com/brianmario/mysql2/issues/923#issuecomment-361346864
but be aware that at step #3 instead of 但请注意,在步骤3而不是
cd "C:\\Ruby24-x64\\bin\\ruby" extconf.rb --with-mysql-dir="C:\\Program Files\\MySQL\\MySQL Connector.C 6.1" cd“ C:\\ Ruby24-x64 \\ bin \\ ruby” extconf.rb --with-mysql-dir =“ C:\\ Program Files \\ MySQL \\ MySQL Connector.C 6.1”
I did 我做了
"C:\\Ruby24-x64\\bin\\ruby" extconf.rb --with-mysql-dir="C:\\Program Files (x86)\\MySQL\\MySQL Connector.C 6.1" “ C:\\ Ruby24-x64 \\ bin \\ ruby” extconf.rb --with-mysql-dir =“ C:\\ Program Files(x86)\\ MySQL \\ MySQL Connector.C 6.1”
no "cd" at the begging and my connector was in "C:\\Program Files (x86)" folder. 乞求处没有“ cd”,并且我的连接器位于“ C:\\ Program Files(x86)”文件夹中。
also at step #6 I was copying 同样在步骤6,我正在复制
C:\\Ruby24-x64\\lib\\ruby\\gems\\2.4.0\\gems\\mysql2-0.4.10-x64-mingw32\\ext\\mysql2\\mysql2.so C:\\ Ruby24-x64 \\ lib \\ ruby \\ gems \\ 2.4.0 \\ gems \\ mysql2-0.4.10-x64-mingw32 \\ ext \\ mysql2 \\ mysql2.so
to newly created folder 到新创建的文件夹
C:\\Ruby24-x64\\lib\\ruby\\gems\\2.4.0\\gems\\mysql2-0.4.10-x64-mingw32\\lib\\mysql2\\2.4 C:\\ Ruby24-x64 \\ lib \\ ruby \\ gems \\ 2.4.0 \\ gems \\ mysql2-0.4.10-x64-mingw32 \\ lib \\ mysql2 \\ 2.4
compiling process was showing plenty warnings but eventually rake db:migrate started work for me, so should yours code 编译过程中显示了大量警告,但最终rake db:migrate开始为我工作,所以您的代码也应该如此
Please install Mysql server . 请安装Mysql服务器。 Install below gems. 安装在宝石下面。
Libmysqlclient-dev Or Mysql-devl Libmysqlclient-dev或Mysql-devl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.