[英]Rails cannot connect to mySQL
I have been trying to set up an Apache server utilizing Ruby on Rails and mySQL through Phusion Passenger. 我一直在尝试通过Phusion Passenger利用Ruby on Rails和mySQL建立一个Apache服务器。 I have Apache v2.2.3, Passenger v3.0.13, Ruby v1.9.3, Rails v3.2.6, and mySQL v5.0.95.
我有Apache v2.2.3,Passenger v3.0.13,Ruby v1.9.3,Rails v3.2.6和mySQL v5.0.95。
Earlier, I encountered problems due to an incorrect Javascript runtime, but I was able to fix that by installing execjs and therubyracer. 早些时候,由于Javascript运行时不正确,我遇到了问题,但是我能够通过安装execjs和therubyracer来解决此问题。 I was successfully able to create the website with SQLite, but I need to use mySQL instead.
我可以使用SQLite成功创建网站,但是我需要使用mySQL。
Now, I have created a new project with the command "rails new myProject -d mysql" and added the appropriate gems to my Gemfile (that is, "gem 'mysql2','0.3.11'"; "gem 'execjs'"; and "gem 'therubyracer'"). 现在,我使用命令“ rails new myProject -d mysql”创建了一个新项目,并将适当的gem添加到了我的Gemfile中(即“ gem'mysql2','0.3.11'“;” gem'execjs'“ ; and“ gem'therubyracer'”)。
My database.yml file looks like this (the test and production parts only differ in terms of name) : 我的database.yml文件如下所示(测试部分和生产部分仅在名称方面有所不同):
development:
adapter: mysql2
encoding: utf8
database: myProject_development
pool: 5
username: root
password:
host: localhost
socket: /var/lib/mysql/mysql.sock
Now, the problem is not immediately apparent. 现在,问题并没有立即显现出来。 From terminal, I cannot find any problems (that is, "rake db:create" runs correctly, no errors appear upon scaffolding, etc.), but when I visit the website, Passenger displays the following error:
在终端上,我找不到任何问题(即“ rake db:create”正确运行,在脚手架上没有出现错误等),但是当我访问该网站时,Passenger显示以下错误:
And none of the webpages appear. 而且没有任何网页出现。 So, where is my fault?
那么,我的错在哪里? I believe my Gemfile is correct, my database.yml seems to be updated, I can access mySQL from terminal, and I was able to run the website in SQLite.
我相信我的Gemfile是正确的,我的database.yml似乎已更新,可以从终端访问mySQL,并且能够在SQLite中运行网站。 Any suggestions would be appreciated!
任何建议,将不胜感激!
EDIT: My gemfile: 编辑:我的gemfile:
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'
EDIT: Output of "bundle list": 编辑:“捆绑清单”的输出:
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)
EDIT: Oh, and I'm working off of CentOS 5.8 , by the way. 编辑:哦,我正在使用CentOS 5.8 。
Add the following to your Gemfile: 将以下内容添加到您的Gemfile中:
gem 'mysql2'
Next run 下一轮
bundle install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.