Windows下Ruby on rails 连接mysql数据库失败的解决方法

在Windows下折腾Ruby on rails,总会碰到各种各样你所意想不到的问题,所以过来人一般都会叫你用Linux吧,有条件的直接上Mac,但是对于我们这种苦逼的校园网用户来说,用Linux吧,校园网客户端不支持,Mac?屌丝用的???下面直接切入正题。。。

今天在学校Ruby on rails的时候,就遇到了一个无法连接数据库的问题。我装的rails版本是3.2.1,默认的数据库是Sqlite3,但对于习惯了mysql的用户来说,还是用会mysql吧。

错误提示:mysql2::error <can't connect to mysql server on 'localhost' <10061>,经过一番Google之后,问题得到了解决。大概的原因是你的电脑开启了IPV6的支持,当你访问localhost的时候,跳转到本机,而不是127.0.0.1,所以导致出错。原文是这样描述的My best guess is that the machine, which you indicated as Windows, has IPv6 networking enabled. Thus when you try to go to localhost, it is resolving to "::1". This is in fact the local machine, however, default MySQL installs normally have bind-address set to 127.0.0.1, which would cause localhost to fail in this setup.其实我也不是弄得很清楚,还望能够理解的朋友帮忙解释一下。好吧,ping一下localhost,看返回的是什么,如果是来自 ::1的回复。。。那就直接修改一下hosts文件就可以解决问题了。PS:win7中的hosts文件在C:\Windows\System32\drivers\etc目录下,增加一行127.0.0.1 hostlocal就行了。

posted @ 2012-10-15 17:35  helloxyz  Views(497)  Comments(0Edit  收藏  举报