Rails无法连接到mySQL

时间:2012-07-10 22:28:21

标签: mysql ruby-on-rails apache

我一直在尝试使用Ruby on Rails和mySQL通过Phusion Passenger建立一个Apache服务器。我有Apache v2.2.3,Passenger v3.0.13,Ruby v1.9.3,Rails v3.2.6和mySQL v5.0.95。

之前,由于Javascript运行时不正确,我遇到了问题,但我能够通过安装execjs和therubyracer来解决这个问题。我成功地用SQLite创建了网站,但我需要使用mySQL。

现在,我使用命令“rails new myProject -d mysql”创建了一个新项目,并将相应的gem添加到我的Gemfile中(即“gem'mysql2','0.3.11'”;“gem” execjs'“;和'gem'therubyracer'”)。

我的database.yml文件看起来像这样(测试和生产部分只在名称上有所不同):

development:
  adapter: mysql2
  encoding: utf8
  database: myProject_development
  pool: 5
  username: root
  password:
  host: localhost
  socket: /var/lib/mysql/mysql.sock

现在,问题并不是立即显现出来的。从终端,我找不到任何问题(即“rake db:create”正确运行,脚手架上没有出现错误等),但是当我访问网站时,Passenger显示以下错误:

无法启动Ruby(Rack)应用程序

在任何来源(Bundler :: GemNotFound)中都找不到mysql2-0.3.11

没有网页出现。那么,我的错在哪里?我相信我的Gemfile是正确的,我的database.yml似乎更新了,我可以从终端访问mySQL,我能够在SQLite中运行该网站。任何建议将不胜感激!

编辑:我的宝石文件:

source 'https://rubygems.org'

gem 'rails', '3.2.6'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2','0.3.11'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server                     
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

gem 'execjs'
gem 'therubyracer'

编辑:输出“捆绑列表”:

Gems included by the bundle:
  * actionmailer (3.2.6)
  * actionpack (3.2.6)
  * activemodel (3.2.6)
  * activerecord (3.2.6)
  * activeresource (3.2.6)
  * activesupport (3.2.6)
  * arel (3.0.2)
  * builder (3.0.0)
  * bundler (1.1.4)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.3.3)
  * erubis (2.7.0)
  * execjs (1.4.0)
  * hike (1.2.1)
  * i18n (0.6.0)
  * journey (1.0.4)
  * jquery-rails (2.0.2)
  * json (1.7.3)
  * libv8 (3.3.10.4)
  * mail (2.4.4)
  * mime-types (1.19)
  * multi_json (1.3.6)
  * mysql2 (0.3.11)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-cache (1.2)
  * rack-ssl (1.3.2)
  * rack-test (0.6.1)
  * rails (3.2.6)
  * railties (3.2.6)
  * rake (0.9.2.2)
  * rdoc (3.12)
  * sass (3.1.20)
  * sass-rails (3.2.5)
  * sprockets (2.1.3)
  * therubyracer (0.10.1)
  * thor (0.15.4)
  * tilt (1.3.3)
  * treetop (1.4.10)
  * tzinfo (0.3.33)
  * uglifier (1.2.6)

编辑:哦,顺便说一句,我正在使用 CentOS 5.8

1 个答案:

答案 0 :(得分:0)

将以下内容添加到您的Gemfile:

gem 'mysql2'

下次运行

bundle install