rails出现Can't connect to MySQL server on 'localhost' (10061)问题的解决方法

rails3 跑在win7下面,装了mysql,cmd里面mysql -u 和telnet 都没问题,但是rails3 执行rake db:create的时候出现Can't connect to MySQL server on 'localhost' (10061)的错误

后几经google,国外同行也有类似问题,问题描述的也比较清楚,原帖如下:
I'm trying to install ROR with a MySQL backend on a Windows 7 x64 box but they are not working together. When I did this before several months ago, it was just a mysql install and a bundle command but not this time.

I've installed MySQL 5.1 32 bit on a path with no spaces and configured the server. I had to install the mysql2 gem using the command line arguments to specify the mysql instance path to get the gem to install. However, rake db:create fails with a Can't connect to MySQL server on 'localhost' (10061) error.

I have verifed that mysql is running on the specified port. mysql, mysqladmin, and telnet localhost 3306 all work as normal. I have a firewall exception for port 3306 and it works fine. I've also turned the firewall off and it makes no difference.

I've spent hours going though google and trying many possibilities without success. Most of the documentation I have found relates to issues where mysql is not running / running on a pipe but this is not my problem.

database.yml excerpt:
common:&common
adapter: mysql2
encoding: utf8
reconnect:false
pool:5
username: root
password: root
#host: 127.0.0.1
host: localhost
port:3307


development:
<<:*common
database: project_dev
 
Any ideas how to fix this?
 
edited  Jan 18 at 20:09
 
asked  Jan 18 at 19:52
 
 
虽然老外也是很多驴头不对马嘴的情况,不过还是有靠谱的答案:
大意是因为ipv6的原因导致的。
两种解决之道
1种是修改database.yml的配置host: 127.0.0.1
另种是修改mysql.ini,修改或者增加bing-address
bind-address=localhost

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.

You might be able to verify this by running ping localhost from the command prompt, and seeing if you get a response like:

 Reply from::1: time<1ms

To fix this, you can change your config to specify:

 host:127.0.0.1

Alternately, you can change MySQL's configuration to allow a different bind-address, e.g. localhost instead of 127.0.0.1.

answered  May 29 at 4:33
772 2 10

转载于:https://www.cnblogs.com/linbirg/archive/2012/07/19/2600366.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值