我正在努力自学SQL和Ruby on Rails,而且刚刚开始。 我正在按照教程进行操作,并成功创建了一个新的SQL数据库和用户以及一个项目。
下一步是运行架构转储(即使数据库目前为空(,只是为了确认项目可以与新数据库通信。 不幸的是,这是不行的。 我可以看到我的config/database.yml中列出的数据库,它包含对用户和数据库的正确引用,但由于某种原因,模式转储失败。
下面是我的命令,然后是错误,然后是带有跟踪的命令。 我非常感谢你能提供的任何帮助。
C:UsersDannyDocumentsSitesdemo_project>rails db:schema:dump
rails aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/Users/Danny/Documents/Sites/demo_project/config/application.rb:7:in `<top (required)>'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `require_relative'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
C:UsersDannyDocumentsSitesdemo_project>rails db:schema:dump --trace
rails aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `require'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:81:in `require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:81:in `block (2 levels) in require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:76:in `each'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:76:in `block in require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:65:in `each'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:65:in `require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler.rb:114:in `require'
C:/Users/Danny/Documents/Sites/demo_project/config/application.rb:7:in `<top (required)>'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `require_relative'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `<top (required)>'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:703:in `raw_load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:104:in `block in load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:103:in `load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
在下面提到的命令中,您需要自己编译
C:Usersxxxxxxxx>gem install mysql2 --platform=ruby -- '--with-mysql-lib="I:mysql-5.7.19-winx64lib" --with-mysql-include="I:mysql-5.7.19-winx64include"'
如果仍然遇到错误,则可能需要降级到2.3才能获得mysql支持。
对于Windows上rails的mysql兼容性。请在下面找到GitHub链接:
https://github.com/brianmario/mysql2/issues/861