0

我很难让 Ruby 连接到 mySQL。我可以让 MYSQL 使用 mySQL 工作台进行连接,这很好。这是我尝试运行 DBConsole 时遇到的错误。

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

我在 GoDaddy 帐户上的数据库上运行,因此我无法向该用户授予所有权限。我打电话给godaddy,他们发誓他们的“RoR”部门能够使用我的设置进行连接。说到这里,这里是database.yml文件。

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

在相关/不相关的注释中,我无法安装 mySQL2 gem,所以我使用的是 mySQL。

编辑:整个 database.yml 文件

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
4

2 回答 2

0

您的 SQL 服务器上是否安装了 PHPMyAdmin?通常,每当我创建新用户时,我都会通过 PHPMyAdmin 并在我正在使用的 RoR 的数据库上设置具有授予访问权限的用户。您的 database.yml 看起来不错,问题出在 SQL 方面。

于 2011-05-09T03:38:48.663 回答
0

当您部署到 godaddy 时,您是否使用生产设置,而不是开发设置?我没有使用 godaddy 托管 Rails 应用程序的经验,但他们可能会将所有托管应用程序配置为默认为生产环境(许多 rails 主机都这样做)。因此,如果它使用不同的环境,它可能没有使用您期望的用户名/密码组合。

您可能还想尝试通过编写一个快速而肮脏的 PHP 测试脚本来测试您的凭据,如下所示:

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

mysql_close($con);

另外,上面说它失败了,但它正在尝试使用 user 'coffeetowndev'@'localhost'。您必须确保使用以下内容向该用户授予权限:

grant select,insert,update,delete on coffeetowndev.* to 'coffeetowndev'@'localhost' identified by ********
于 2011-05-09T03:41:14.347 回答