gpt4 book ai didi

mysql - ruby on Rails 无法访问 mysql

转载 作者:行者123 更新时间:2023-11-29 14:52:04 24 4
gpt4 key购买 nike

我正在尝试在 Rails 中运行我的第一个简单项目。我已经安装了wamp。并尝试使用与 wamp 安装的相同 mysql 数据库服务器。但我决定使用 webrick,而不是 apache。希望配置能更简单。我编辑了项目目录下的database.yml文件和gemfile:

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost

# 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: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost

production:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost

这是 gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.5'

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

gem 'mysql'

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

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'

# end

我使用了 gem install mysql 命令,因为 mysql2 不适合我。

enter image description here

我所做的是启动 wampserver 并停止 apache 服务。加载需要很长时间: http://localhost:3000/rails/info/properties然后 webrick 就会崩溃。但如果我不启动 wamp,我会得到以下信息: enter image description here

最佳答案

您是否将 mysql 配置为在 3306 以外的端口上运行?如果您使用的端口不同,则需要进行如下编辑:

development:
adapter: mysql
encoding: utf8
reconnect: false
database: rubybeg_test
pool: 5
username: root
password: 1234
host: localhost
port: 3306 #replace with the correct port

如果这不起作用,还可以尝试将 localhost 更改为 127.0.0.1 以强制其使用 TCP。有时它尝试使用套接字但找不到套接字文件。

关于mysql - ruby on Rails 无法访问 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com