【问题标题】:MySQL gem only accessable from ruby command line, not apache localhostMySQL gem 只能从 ruby​​ 命令行访问,而不是 apache localhost
【发布时间】:2012-09-01 06:58:47
【问题描述】:

注意,ruby n00b 试水 -

操作系统 - OSX 10.7

/Library/WebServer/CGI-Executables 中的test.rb:

#!/usr/bin/ruby
require 'mysql'

con = Mysql.new('localhost', 'root', 'root', 'rubytest')
rs = con.query('select * from people')
rs.each_hash { |h| puts h['name']}  
con.close

从命令行ruby test.rb 运行时,我得到的字段很好。当从 localhost (http://localhost/cgi-bin/test.rb) 访问 test.rb 时,我在错误日志中得到 500 和一个关于 mysql 丢失的唠叨-

Apache 错误日志:

[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] /Library/WebServer/CGI-Executables/test.rb:3:in `require': no such file to load -- mysql (LoadError)
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] \tfrom /Library/WebServer/CGI-Executables/test.rb:3
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] Premature end of script headers: test.rb

我在 ~/.bashrc 中的导出路径:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
export PATH="$PATH:/usr/local/mysql/bin"
export PS1="$ "

如果有帮助,请运行gem env | grep 'RUBY EXECUTABLE'

RUBY EXECUTABLE: /Users/robertcox/.rvm/rubies/ruby-1.9.2-p318/bin/ruby

任何帮助表示赞赏

【问题讨论】:

  • 只是为了确定:您将 ruby​​ 用于纯 cgi 脚本,而不是与 rails 框架连接?
  • 看看这里,如果对你有帮助的话。你可能只是不够。 stackoverflow.com/questions/5664553/…

标签: mysql ruby apache


【解决方案1】:

也许你需要更新gem install mysql2

【讨论】:

    猜你喜欢
    • 2011-07-17
    • 2021-05-12
    • 2019-08-15
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    相关资源
    最近更新 更多