Access denied for user 'root'@'localhost' (using password: YES)
我设置了一个新环境,其中mysql没有密码以及我是如何收到此错误的。我在哪里更改
'root'@'localhost' (using password: YES)
我的database.yml显示在我的数据库下面是sample_app
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: mysql2
database: db/development.mysql2
pool: 5
timeout: 5000
database: sample_app
username: root
socket: /tmp/mysql.sock
# 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
database: db/test.mysql2
pool: 5
timeout: 5000
database: sample_app
username: root
socket: /tmp/mysql.sock
production:
adapter: mysql2
database: db/production.mysql2
pool: 5
timeout: 5000
database: sample_app
username: root
socket: /var/run/mysqld/mysqld.sock
答案 0 :(得分:1)
您不应该使用root连接到带有应用程序的数据库。创建一个带有名称的新用户/密码,以识别它正在用于特定的app \ task,然后使用它而不是root。
为空密码password:
production:
adapter: mysql2
database: db/production.mysql2
pool: 5
timeout: 5000
database: sample_app
username: root
password:
socket: /var/run/mysqld/mysqld.sock
如果仍然拒绝访问,则数据库会说用户\密码无效
答案 1 :(得分:1)
如果是这样,
$ mysql -u root
带你到mysql然后这将工作,
production:
adapter: mysql2
database: db/production.mysql2
pool: 5
timeout: 5000
database: sample_app
username: root
password:
socket: /var/run/mysqld/mysqld.sock
如果您为root用户设置了一些密码,请尝试
$ mysql -u root -p
<<It will prompt for a password, key it in>>
如果这会带你到mysql,那么这将有效,
production:
adapter: mysql2
database: db/production.mysql2
pool: 5
timeout: 5000
database: sample_app
username: root
password: <<password>>
socket: /var/run/mysqld/mysqld.sock
故事的道德:
首先,尝试使用命令行中的mysql命令登录mysql,看看它是否有效。 然后,在database.yml中使用这些凭据并从rails应用程序登录到mysql。