[英]MYSQL Access denied ruby script in Rails app
I have a Rails 4.2 application deployed to an Ubunutu 14.4 Trusty server. 我有一个部署到Ubunutu 14.4 Trusty服务器的Rails 4.2应用程序。 The issue I'm having right now is being unable to run a script that saves records for me.
我现在遇到的问题是无法运行为我保存记录的脚本。 I get this error:
我收到此错误:
Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)
I've configured the production database to use username root with the right password, yet after restarting the server and trying out the new configuration I get the above error. 我已经将生产数据库配置为使用带有正确密码的用户名root,但在重新启动服务器并尝试新配置后,我得到了上述错误。
I'm running to script by navigating to lib/ on the server and running ruby script9000.rb
. 我通过导航到服务器上的lib /并运行
ruby script9000.rb
运行ruby script9000.rb
。 The script runs fine until it tries to save a record. 该脚本运行正常,直到它尝试保存记录。
Why might this be happening? 为什么会发生这种情况?
The script trips up at Year.find_or_create_by
该脚本在
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)
It is MySQL error, that means that you are trying to connect to database with the user root from localhost with blank or no password. 这是MySQL错误,这意味着您尝试使用localhost的用户root连接到数据库,空白或没有密码。 Make sure, you have user root@localhost on your mysql server or make sure to provide right password.
确保您的mysql服务器上有用户root @ localhost或确保提供正确的密码。
It could be coming from several issues as you describe your workflow. 在描述您的工作流程时,它可能来自几个问题。
From the small context: run your script with RAILS_ENV=production ruby script9000.rb
从小上下文:使用
RAILS_ENV=production ruby script9000.rb
运行脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.