作者:奇奇丶承诺 | 来源:互联网 | 2023-05-18 21:14
我使用SQLite作为我的Rails项目但是当我听说Heroku不支持SQLite时,我切换到了MYSQL.
切换我的数据库后,我启动了我的rails服务器"rails s",但它给了我以下错误:
C:\Sites\simple_cms>rails server
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require'
: cannot load such file -- mysql2/2.2/mysql2 (LoadError)
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.rb:2
:in `'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `r
equire'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `<
top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:76:in `requ
ire'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:76:in `bloc
k (2 levels) in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:72:in `each
'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:72:in `bloc
k in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:61:in `each
'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:61:in `requ
ire'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler.rb:134:in `require'
from C:/Sites/simple_cms/config/application.rb:7:in `'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks
.rb:78:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks
.rb:78:in `block in server'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks
.rb:75:in `tap'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks
.rb:75:in `server'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks
.rb:39:in `run_command!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `'
from bin/rails:4:in `require'
from bin/rails:4:in `'
这是我的gemfile:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use mysql as the database for Active Record
gem 'mysql2'
我彻底搜查,找到了一些答案但是没有用.
我粘贴了我的libmysql.dll
文件Program Files/MySQL Server 5.6
,Ruby/bin
但仍然没有运气.我执行了以下命令:
gem uninstall mysql2
gem install mysql2 --platform=ruby
我按照本教程仍然得到了同样的错误:错误"...无法加载此类文件 - mysql2/2.0/mysql2(LoadError)".在带有Ruby 2.0.0的Windows XP上
如果有人帮助我,我将非常感激,以便我可以将它部署到Heroku.
谢谢.
1> Richard Peck..:
问题是mysql2
gem没有安装其原生依赖项.在以前的Ruby版本中,这会触发unable to build native gem extension
错误:
有些东西已经改变,Ruby 2.2
所以你可以在不构建原生扩展的情况下安装gem.这并不意味着问题得到解决 - 因此您必须确保使用适当的依赖项安装gem.
教程:
从MYSQL下载C-Connector(注意你的Ruby版本 - 如果你使用64位,下载64位版本)
将MYSQL C-Connector文件夹解压缩/安装到您的HDD上(路径中没有任何空格)
运行以下命令: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/your-mysql-connector-path"'
这应该使用它需要的文件安装gem
然后,你可以复制libmysql.dll
从C:/your-mysql-connector-path
/你-红宝石安装/ bin`:>Ç -
这个安装和前一个安装之间的区别在于,应该提到正在安装本机gem扩展(This could take a while
),这表明Ruby正在查看库.
这次,如果安装正确,它应该适合你.
-
如果您仍然看到错误,则必须卸载系统上任何现有版本的mysql2
gem:
如果您收到错误,只需键入gem unstally mysql2
,选择all
然后重复上述步骤即可.