Rails - Access denied for user 'root'@'localhost' ...

Discussion in 'Ruby' started by Jim Cochrane, Jun 23, 2008.

  1. Jim Cochrane

    Jim Cochrane Guest

    I suppose I should post this in a Rails mailing list or wiki, but the
    medium I'm used to is USENET, so I thought I'd try here first. (I don't
    think there's a Rails newsgroup - please correct me if I'm wrong -
    and I see some Rails postings here sometimes, so I'm assuming this
    is appropriate.)

    I'm using the book "Ajax on Rails" to learn about Rails development and
    after following along for the first example, in chapter 2 (pg 20), I'm
    encountering the error:

    #28000Access denied for user 'root'@'localhost' (using password: NO)

    This happens with the browser pointed to (as the book says to do):

    http://localhost:3000/chapter2/myaction

    This is after following the instructions to do:

    script/generate controller chapter2 myaction

    (which was after doing 'rails ajaxonrails; cd ajaxonrails' and starting
    the server)

    I suspect the problem is that the book forgot to tell me that I need to
    create a database for the application and configure it. Is this the
    case or should a database not be needed yet at this point - perhaps
    something unforeseen is going wrong?

    The complete error message I'm getting is:

    Mysql::Error in Chapter2Controller#myaction

    #28000Access denied for user 'root'@'localhost' (using password: NO)


    Thanks!

    --
    Jim Cochrane, Jun 23, 2008
    #1
    1. Advertising

  2. Jim Cochrane

    James Britt Guest

    Jim Cochrane wrote:
    > I suppose I should post this in a Rails mailing list or wiki, but the
    > medium I'm used to is USENET, so I thought I'd try here first. (I don't
    > think there's a Rails newsgroup - please correct me if I'm wrong -
    > and I see some Rails postings here sometimes, so I'm assuming this
    > is appropriate.)
    >
    > I'm using the book "Ajax on Rails" to learn about Rails development and
    > after following along for the first example, in chapter 2 (pg 20), I'm
    > encountering the error:
    >
    > #28000Access denied for user 'root'@'localhost' (using password: NO)


    This looks like a MySQL user configuration issue.

    Does user 'root' in MySQL have a password?

    Have you created a better use account to use with the application DB?



    --
    James Britt

    www.happycamperstudios.com - Wicked Cool Coding
    www.jamesbritt.com - Playing with Better Toys
    www.ruby-doc.org - Ruby Help & Documentation
    www.rubystuff.com - The Ruby Store for Ruby Stuff
    James Britt, Jun 23, 2008
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    This happens generally when the mysql is not reached by the rails
    applicaiton...
    Probably there must be some super user/sudo user who need to grant the acces
    permissions for mysql to get connected.
    If you can conntect using ruby script/console you can be aware of much whats
    is going on the command.

    On Mon, Jun 23, 2008 at 8:12 AM, Eric Tucker <> wrote:

    > I have had some issues using a blank mysql password / no password on some
    > boxes. Not sure if it's rails or mysql, but try using a password.
    > Sent wirelessly via BlackBerry from T-Mobile.
    >
    > -----Original Message-----
    > From: James Britt <>
    >
    > Date: Mon, 23 Jun 2008 11:09:47
    > To: <To%> (ruby-talk ML)
    > Subject: Re: Rails - Access denied for user 'root'@'localhost' ...
    >
    >
    > Jim Cochrane wrote:
    > > I suppose I should post this in a Rails mailing list or wiki, but the
    > > medium I'm used to is USENET, so I thought I'd try here first. (I don't
    > > think there's a Rails newsgroup - please correct me if I'm wrong -
    > > and I see some Rails postings here sometimes, so I'm assuming this
    > > is appropriate.)
    > >
    > > I'm using the book "Ajax on Rails" to learn about Rails development and
    > > after following along for the first example, in chapter 2 (pg 20), I'm
    > > encountering the error:
    > >
    > > #28000Access denied for user 'root'@'localhost' (using password: NO)

    >
    > This looks like a MySQL user configuration issue.
    >
    > Does user 'root' in MySQL have a password?
    >
    > Have you created a better use account to use with the application DB?
    >
    >
    >
    > --
    > James Britt
    >
    > www.happycamperstudios.com - Wicked Cool Coding
    > www.jamesbritt.com - Playing with Better Toys
    > www.ruby-doc.org - Ruby Help & Documentation
    > www.rubystuff.com - The Ruby Store for Ruby Stuff
    >
    >
    kranthi reddy, Jun 23, 2008
    #3
  4. Jim Cochrane

    Jim Cochrane Guest

    On 2008-06-23, Jim Cochrane <> wrote:
    > I suppose I should post this in a Rails mailing list or wiki, but the
    > medium I'm used to is USENET, so I thought I'd try here first. (I don't
    > think there's a Rails newsgroup - please correct me if I'm wrong -
    > and I see some Rails postings here sometimes, so I'm assuming this
    > is appropriate.)
    >
    > I'm using the book "Ajax on Rails" to learn about Rails development and
    > after following along for the first example, in chapter 2 (pg 20), I'm
    > encountering the error:
    >
    > #28000Access denied for user 'root'@'localhost' (using password: NO)
    >
    > This happens with the browser pointed to (as the book says to do):
    >
    > http://localhost:3000/chapter2/myaction
    >
    > This is after following the instructions to do:
    >
    > script/generate controller chapter2 myaction
    >
    > (which was after doing 'rails ajaxonrails; cd ajaxonrails' and starting
    > the server)
    >
    > I suspect the problem is that the book forgot to tell me that I need to
    > create a database for the application and configure it. Is this the
    > case or should a database not be needed yet at this point - perhaps
    > something unforeseen is going wrong?
    >
    > The complete error message I'm getting is:
    >
    > Mysql::Error in Chapter2Controller#myaction
    >
    > #28000Access denied for user 'root'@'localhost' (using password: NO)
    >
    >
    > Thanks!
    >


    I found a fix for the problem, so I'll answer my own question in case it
    will help someone else with the same problem.

    I did the following things to fix it:

    - run mysql_setpermission and use its interactive interface to allow the
    mysql root user to do everything (need to know the mysql root pw).

    - use the mysql command to connect as root and create the needed database
    (in this case, ajaxonrails_development).

    - In database.yml, make sure username is root and fill in the password
    field for the mysql root pw (or change the username to another mysql
    user and the password to that user's password).

    (Running mysql 14.12 on ubuntu 8.04 with rails 2.0.2-1; mysql, installed
    via apt-get, was apparently initialized with only ordinary user
    privileges for root.)

    --
    Jim Cochrane, Jun 23, 2008
    #4
  5. Jim Cochrane

    Dave Cheney Guest

    If I can suggest that using the root account on mysql is not
    considered best practice. I would setup an account for your
    application thusly

    mysql> grant all on yourapp_production.* to 'yourapp'@'<your hostname
    or %>' identified by 'decent_password';
    mysql> flush privileges;

    http://dev.mysql.com/doc/refman/5.0/en/grant.html

    Cheers

    Dave

    On 23/06/2008, at 5:48 PM, Jim Cochrane wrote:

    > I found a fix for the problem, so I'll answer my own question in
    > case it
    > will help someone else with the same problem.
    >
    > I did the following things to fix it:
    >
    > - run mysql_setpermission and use its interactive interface to
    > allow the
    > mysql root user to do everything (need to know the mysql root pw).
    >
    > - use the mysql command to connect as root and create the needed
    > database
    > (in this case, ajaxonrails_development).
    >
    > - In database.yml, make sure username is root and fill in the
    > password
    > field for the mysql root pw (or change the username to another mysql
    > user and the password to that user's password).
    >
    > (Running mysql 14.12 on ubuntu 8.04 with rails 2.0.2-1; mysql,
    > installed
    > via apt-get, was apparently initialized with only ordinary user
    > privileges for root.)
    Dave Cheney, Jun 23, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    781
    Jiong Feng
    Nov 19, 2003
  2. Alex
    Replies:
    4
    Views:
    546
    Hasani Blackwell
    Feb 8, 2005
  3. =?Utf-8?B?S2VuTGVl?=
    Replies:
    5
    Views:
    2,679
  4. EdwardH

    Localhost isn't localhost

    EdwardH, Sep 29, 2005, in forum: Java
    Replies:
    20
    Views:
    6,346
    Roedy Green
    Oct 1, 2005
  5. koicat
    Replies:
    0
    Views:
    208
    koicat
    Jul 2, 2010
Loading...

Share This Page