MYSQL Rails 应用中的 ruby 脚本被拒绝访问

MYSQL Access denied ruby script in Rails app

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

Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)

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

我是 运行 通过导航到服务器上的 lib/ 和 运行ning 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
Access denied for user 'root'@'localhost' (using password: NO)

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

在您描述您的工作流程时,它可能来自几个问题。

从小上下文来看:运行 你的脚本 RAILS_ENV=production ruby script9000.rb