我是ruby on rails的新手,我正试图让它与MySQL一起工作。我用brew install mysql安装了mysql然后我安装了gem mysql2但没有任何作用。我已经在这里完成了所有问题,似乎没有任何工作。这是我的database.yml
# MySQL. Versions 5.0+ are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
host: localhost
development:
<<: *default
database: optimus_development
# 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:
<<: *default
database: optimus_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: optimus_production
username: optimus
password: <%= ENV['OPTIMUS_DATABASE_PASSWORD'] %>
这是我尝试在浏览器中运行时出现的错误:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
我尝试将更改localhost更改为127.0.0.1,但这不起作用。任何援助将不胜感激
我在阅读下面可能的重复链接后,我启动了我的服务器,现在我收到了这条消息:
Unknown database 'optimus_development'Run `$ bin/rake db:create db:migrate` to create your database
答案 0 :(得分:0)
确保您的MySQL服务器已启动:
Apple Menu > System Preferences > MySQL > Start MySQL Server
答案 1 :(得分:0)
我明白了。我不得不使用&#34; mysql.server start&#34;从终端运行mysql服务器。然后我不得不运行&#34; bin / rake db:create db:migrate&#34;它之后起作用了