【问题标题】:Error when starting Rails server with MySQL使用 MySQL 启动 Rails 服务器时出错
【发布时间】:2014-03-11 15:22:59
【问题描述】:

我在 Windows 7 上的 Ruby 2.0.0 上运行 Rails 4.0.3,并安装了 DevKit(所有 x64)。 我使用subst X: "C:\Program Files\MySQL\MySQL Server 5.6"gem install mysql2 --platform=ruby -- --with-mysql-dir=X: 安装了mysql2 gem,它安装得很好。然后我使用rails new mysql_testy 创建了一个运行良好的新应用程序,但是当我运行rails server 时出现以下错误:

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2.rb:8:in 'require': 193: %1 is not a valid Win32 application.   - C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2/mysql2.so (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2.rb:8:in '<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in 'block (2 levels) in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in 'each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in 'block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in 'each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler.rb:131:in 'require'
from C:/Users/Liam/Ruby/mysql_testy/config/application.rb:7:in '<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in 'block in <top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in 'tap'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in '<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'`

你们知道发生了什么吗?

【问题讨论】:

  • 这个问题的答案应该可以解决你的问题:stackoverflow.com/questions/10468118/…
  • @rails4guides.com:在那个问题中,提问者安装了 mysql2 gem 的预编译二进制版本,而这里它是使用 DevKit 安装的,用于为我的系统构建本机扩展。此外,当我按照我在网上找到的指南尝试使用 Ruby 1.9.3 时(就像您链接到的问题的第一个答案),我什至没有正确安装 mysql2。
  • 看来问题是Ruby是Win32,而你的MySql是Win64,导致出现不兼容错误。这篇文章或许能解决你的问题:blog.mmediasys.com/2011/07/07/…
  • 你确定我的 Ruby 是 Win32 吗?我明确安装了 x64 版本的 Ruby...

标签: mysql ruby-on-rails ruby ruby-on-rails-4 webrick


【解决方案1】:

不确定您是否已经解决了,但我遇到了同样的问题。我安装了 32 位 sql 连接器,从中复制了 libmysql.dll 文件并将其粘贴到 Ruby/bin 文件夹中。打开一个新的命令提示符并能够连接到服务器。

在此步骤之前,您可能需要重新安装指向连接器路径的全新 MySQL2 gem:gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\mysql-connector-c-6.1.5-win32\lib" --with-mysql-include="C:\mysql-connector\mysql-connector-c-6.1.5-win32\include" --with-mysql-dir="C:\mysql-connector"'

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-05
    • 2012-04-18
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多