我在Windows 7计算机上安装了Ruby on Rails,MySQL Server 5.6和mysql2 gem。 MySQL Server 5.6在端口3000上运行。我的database.yml文件是:
# MySQL2
# gem install mysql2
# Ensure the mysql2 gem is defined in your Gemfile
# gem 'mysql2'
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1_development
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1_test
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo1
pool: 5
username: root
password: root
host: 127.0.0.1
port: 3000
我使用以下Gemfile运行“bundle install”:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use mysql2 as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
gem 'devise'
gem 'protected_attributes'
gem 'terminator'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
我可以毫无问题地运行“bundle install”,“rake db:create”和“rake db:migrate”命令。我启动了MySQL服务器并在命令行中输入“rails s”。结果如下: WARN TCPServer错误:权限被拒绝 - 绑定(2) 离开
我确保在Windows防火墙中打开端口3000,并允许rails通过防火墙进行通信。
键入“rails s -p 80”,并且Web应用程序在localhost:80上运行,但这些字段不起作用,因为MySQL Server不能在端口80上运行。
我错过了什么吗?如何让Rails服务器和Web应用程序运行?
答案 0 :(得分:0)
看起来你正试图在端口3000上运行数据库和rails web服务器。
编辑:为了澄清,你应该在端口3000(默认)运行rails服务器,并在另一个端口上运行mysql。
无论您运行mysql的是什么端口,请将该端口放在“port:”下的database.yml设置中。
答案 1 :(得分:0)
我认为你应该使用3306端口?这就是我的连接字符串的样子,它工作正常。
staging:
adapter: mysql2
encoding: utf8
host: 10.0.0.16
database: my_database
port: 3306
username: my_username
password: my_password
请注意,您的网络服务器端口和数据库是两回事。我通常在端口3000上运行我的web服务器,在3306上运行mysql。我认为3306是用于mysql的默认端口。