rails出现Can't connect to MySQL server on 'localhost' (10061)问题的解决方法
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
edited Jan 18 at 20:09
|
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.