gpt4 book ai didi

mysql - ruby 无法连接 MySQL

转载 作者:行者123 更新时间:2023-11-29 23:19:41 25 4
gpt4 key购买 nike

我是 ruby​​ on Rails 的新手,我正在尝试让它与 MySQL 一起使用。我使用brew install mysql安装了mysql,然后安装了gem mysql2,但没有任何效果。我已经解决了这里的所有问题,但似乎没有任何效果。这是我的数据库.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

最佳答案

确保您的 MySQL 服务器已启动:

Apple Menu > System Preferences > MySQL > Start MySQL Server

关于mysql - ruby 无法连接 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27433678/

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