Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL Access denied ruby script in Rails app

Tags:

I have a Rails 4.2 application deployed to an Ubunutu 14.4 Trusty server. 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.

I'm running to script by navigating to lib/ on the server and running 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

  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
like image 798
Nick Res Avatar asked Jun 27 '16 19:06

Nick Res


1 Answers

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. Make sure, you have user root@localhost on your mysql server or make sure to provide right password.

like image 168
Pavel Katiushyn Avatar answered Sep 29 '22 10:09

Pavel Katiushyn