ruby无法连接MySQL
我是RubyonRails新手,我正在尝试让它与MySQL一起工作。我使用brew安装mysql安装了mysql,然后安装了gem mysql2,但没有任何效果。我已经把这里所有的问题都讨论过了,似乎什么都不管用。这是我的数据库.ymlruby无法连接MySQL,mysql,ruby-on-rails,Mysql,Ruby On Rails,我是RubyonRails新手,我正在尝试让它与MySQL一起工作。我使用brew安装mysql安装了mysql,然后安装了gem mysql2,但没有任何效果。我已经把这里所有的问题都讨论过了,似乎什么都不管用。这是我的数据库.yml # MySQL. Versions 5.0+ are recommended. # # Install the MYSQL driver # gem install mysql2 # #
# 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'] %>
我曾尝试将localhost更改为127.0.0.1,但没有成功。如有任何协助,将不胜感激
我在阅读了下面可能存在的重复链接后启动了服务器,现在收到以下消息:
Unknown database 'optimus_development'Run `$ bin/rake db:create db:migrate` to create your database
确保您的MySQL服务器已启动:
Apple Menu > System Preferences > MySQL > Start MySQL Server
我想出来了。我必须使用“mysql.server start”从终端运行mysql服务器。然后我不得不运行“bin/rake db:create db:migrate”,然后它就开始工作了那么你会遇到什么错误?请始终发布你遇到的错误。本地MySQL服务的一个常见问题是,它们运行在Unix套接字上,其文件不在默认的预期位置,要求您在database.ymlAnd中添加一个
socket:/path/to/mysql.sock
,您说您确实安装了brew mysql
,但是您真的启动了mysql服务器吗?您能在没有Rails的情况下从命令行连接到它吗?Michael Berkowski,我何时添加“socket:/path/to/mysql.sock”?Mysql甚至没有显示在系统首选项窗口中。这是因为我已经安装了mamp,并且它干扰了brew安装的mysql吗?只有使用了具有首选项窗格扩展的mysql安装程序时,这才相关。
Apple Menu > System Preferences > MySQL > Start MySQL Server