Search code examples
mysqlruby-on-railsmysql-error-1045

Ruby on Rails having a rough time connecting to MySQL


I'm having a hard time getting Ruby to connect to mySQL. I can get MYSQL to connect using the mySQL workbench, so that's good. Here is the error I'm getting when I try to run DBConsole.

W:\testMySQL>rails dbconsole
Enter password: ********
ERROR 1045 (28000): Access denied for user 'coffeetowndev'@'localhost' (using pa
ssword: YES)

I'm running on a Database on a GoDaddy account, so I'm not able to grant all privledges to that user. I called godaddy, and they swore their 'RoR' department was able to connect using my settings. Speaking of this, here is the database.yml file.

development:
 adapter: mysql
 encoding: utf8
 reconnect: false
 port: 3306
 database: coffeetowndev
 pool: 5
 username: coffeetowndev
 password: ********
 hostname: coffeetowndev.db.5850247.hostedresource.com

on a related/unrelated note, I'm not able to get mySQL2 gem to install, so I'm using the mySQL one.

edit: entire database.yml file

development:
 adapter: mysql
 encoding: utf8
 reconnect: false
 port: 3306
 database: coffeetowndev
 pool: 5
 username: coffeetowndev
 password: ********
 hostname: coffeetowndev.db.5850247.hostedresource.com

test:
 adapter: mysql
 encoding: utf8
 reconnect: false
 port: 3306
 database: coffeetowntest
 pool: 5
 username: coffeetowntest
 password: ********
 hostname: coffeetowntest.db.5850247.hostedresource.com


production:
 adapter: mysql
 encoding: utf8
 reconnect: false
 port: 3306
 database: coffeetown
 pool: 5
 username: coffeetown
 password: ********
 hostname: coffeetown.db.5850247.hostedresource.com

Solution

  • Are you using the production setting when you deploy to godaddy, instead of the development one? I'm not experienced with using godaddy for hosting Rails apps, but it's possible they configure all hosted applications to default to the production environment (many rails hosts do). Therefore, it may not be using the username/password combination you're expecting if it's using a different environment.

    You may also want to try testing your credentials by coding up a quick and dirty PHP test script, something like this:

    $con = mysql_connect("coffeetowndev.db.5850247.hostedresource.com","coffeetowndev","******");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    echo 'Connected successfully';
    
    mysql_close($con);
    

    Also, above it says it's failing but it's trying to use user 'coffeetowndev'@'localhost'. You must ensure that you granted permissions to that user using somethign like this:

    grant select,insert,update,delete on coffeetowndev.* to 'coffeetowndev'@'localhost' identified by ********