Take the 2-minute tour ×
require 'rubygems'
require 'active_record'

  :adapter => 'mysql2',
  :database => 'vft',
  :user => 'vft',
  :password => 'vft_password'

class Attachment < ActiveRecord::Base


This code throws Access denied for user 'root'@'localhost' (using password: YES) (Mysql::Error) with both mysql and mysql2 gems. The vft user is real and works with vft database through phpmyadmin or console. Here is my environment:

Debian Squeeze, Rails 3.2, RVM Ruby 1.9.3

Same code works good on my local PC(Ubuntu), the problem occurs only on remote VDS...

share|improve this question
If you're using Rails, what is in your database.yml? Rails might override the ActiveRecord connection with that. I am just guessing though. –  iain Jan 22 '12 at 12:00
I've tried this outside Rails environment without success. –  sunki Jan 22 '12 at 12:03

1 Answer 1

up vote 1 down vote accepted

I guess you should replace :user with :username.

share|improve this answer
Thanks a lot! Can u explain why does my code works on local PC and doesn't on other? –  sunki Jan 22 '12 at 12:13
It is probably due to different privileges settings on MySQL. As AR could not find the username options, it falled back to root as the user. Glad it works now. –  Jef Jan 22 '12 at 12:15

Your Answer


