Rails开发-无法连接到“本地主机"上的MySQL服务器(10061) [英] Rails development - Can't connect to MySQL server on 'localhost' (10061)
问题描述
我是使用MySQL作为数据库的Rails开发新手.我可以使用以下命令成功连接到MySQL:
I'm a Rails developer newbie using MySQL as the database. I can successfully connect to MySQL using the command:
MySQL -u macDaddy -p
在命令提示符下输入
,因此我知道用户有效并且MySQL正在运行.但是当我尝试运行
at the command prompt, so I know the user is valid and MySQL is running. But when I try to run
rake db:schema:dump
在命令行中出现此错误: 耙子流产了! 无法连接到本地主机"(10061)上的MySQL服务器
at the command line I get this error: rake aborted! Can't connect to MySQL server on 'localhost' (10061)
我的database.yml有问题吗?在这里:
Is something wrong with my database.yml? Here it is:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: bookmobile
pool: 5
username: macDaddy
password: booklover
host: localhost
socket: mysql
port: 3306
我也尝试删除端口和套接字线路,但仍然遇到相同的错误.请帮忙.这是我的版本: 在Windows 7上进行开发
I've also tried removing the port and socket lines but I still get the same error. Please help. Here are my versions: developing on Windows 7
适用于win64的MySQL Ver 14.14 distrib 5.5.21 服务器版本5.5.21
MySQL Ver 14.14 distrib 5.5.21 for win64 Server version 5.5.21
Rails 3.2.1
Rails 3.2.1
谢谢!
推荐答案
我的最佳猜测是,您表示为Windows的计算机已启用IPv6网络.因此,当您尝试转到本地主机时,它将解析为":: 1".实际上,这是本地计算机,但是,默认的MySQL安装通常将bind-address设置为127.0.0.1,这将导致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.
您可能可以通过在命令提示符下运行ping localhost
并查看是否收到如下响应来验证这一点:
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
或者,您可以更改MySQL的配置以允许使用其他绑定地址,例如本地主机,而不是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.
这篇关于Rails开发-无法连接到“本地主机"上的MySQL服务器(10061)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!