MYSQL Access拒绝了Rails应用程序中的ruby脚本

Nic*_*Res 5 mysql ruby-on-rails-4 ubuntu-14.04

我有一个部署到Ubunutu 14.4 Trusty服务器的Rails 4.2应用程序.我现在遇到的问题是无法运行为我保存记录的脚本.我收到此错误:

Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)
Run Code Online (Sandbox Code Playgroud)

我已经将生产数据库配置为使用带有正确密码的用户名root,但在重新启动服务器并尝试新配置后,我得到了上述错误.

我正在通过导航到服务器上的lib /并运行来运行脚本ruby script9000.rb.该脚本运行正常,直到它尝试保存记录.

为什么会发生这种情况?


剧本绊倒了 Year.find_or_create_by

  def save_record(record)
    sanitize_record(record)
    full_year = complete_year(@@record["year_number"])
    if full_year >= 2014
      year = Year.find_or_create_by(year: full_year)
      year.records.create(@@record)
    end
  end
Run Code Online (Sandbox Code Playgroud)

小智 3

Access denied for user 'root'@'localhost' (using password: NO)
Run Code Online (Sandbox Code Playgroud)

这是 MySQL 错误,这意味着您正在尝试使用root用户从localhost连接到数据库,密码为空或无密码。确保您的 mysql 服务器上有用户 root@localhost 或确保提供正确的密码。