I'm a Rails developer newbie using MySQL as the database. I can successfully connect to MySQL using the command:
我是一个使用MySQL作为数据库的Rails开发新手。我可以使用命令成功地连接到MySQL:
MySQL -u macDaddy -p
at the command prompt, so I know the user is valid and MySQL is running. But when I try to run
在命令提示符下,我知道用户是有效的,MySQL正在运行。但是当我试着跑的时候
rake db:schema:dump
at the command line I get this error: rake aborted! Can't connect to MySQL server on 'localhost' (10061)
在命令行,我得到这个错误:rake aborted!无法连接到本地主机上的MySQL服务器(10061)
Is something wrong with my database.yml? Here it is:
我的数据库出问题了吗,yml?这里是:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: bookmobile
pool: 5
username: macDaddy
password: booklover
host: localhost
socket: mysql
port: 3306
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
我也尝试过删除端口和套接字行,但仍然得到相同的错误。请帮助。以下是我的版本:在Windows 7上开发
MySQL Ver 14.14 distrib 5.5.21 for win64 Server version 5.5.21
对于win64服务器版本5.5.21,MySQL Ver 14.14分配5.5.21。
Rails 3.2.1
Rails 3.2.1之上
Thanks!
谢谢!
7 个解决方案
#1
41
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.
我最大的猜测是,你提到的Windows机器已经启用了IPv6网络。因此,当您尝试进入localhost时,它将解析为“::1”。然而,这实际上是本地机器,默认的MySQL安装通常将绑定地址设置为127.0.0.1,这将导致localhost在此设置中失败。
You might be able to verify this by running ping localhost
from the command prompt, and seeing if you get a response like:
您可以通过从命令提示符运行ping localhost来验证这一点,并查看是否得到如下响应:
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.
或者,您可以更改MySQL的配置,以允许使用不同的绑定地址,例如localhost,而不是127.0.0.1。
#2
4
simply change your host to host:127.0.0.1
只需将主机更改为主机:127.0.0.1
#3
3
Change the value of host in the database.yml to be "127.0.0.1" will work. Or,you can modify your pc's hosts file, add an item as "localhost 127.0.0.1".
更改数据库中主机的值。yml设为“127.0.0.1”即可。或者,您可以修改您的pc主机文件,将一个项目添加为“localhost 127.0.0.1”。
#4
3
I had a similar error but it was because the port: 3306 was missing in the database.yml. Once I added port: 3306 issue was resolved.
我也有类似的错误,但那是因为数据库中缺少端口:3306。一旦我添加了port: 3306,问题就解决了。
#5
1
It's because you don't have password set in your database server(mysql), try this:
因为您的数据库服务器(mysql)没有设置密码,请尝试以下操作:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: bookmobile
pool: 5
username: macDaddy
password:
host: localhost
socket: mysql
port: 3306
#6
1
make sure the port number that you have set while creating MySQL(e.g.: 7777), please add port number with appropriate 'username' and 'password'.
确保创建MySQL时设置的端口号。: 7777),请加上“用户名”及“密码”的端口号。
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: admin
host: localhost
port: 7777
in the database.yml in config directory of your app directory.
在数据库中。在应用程序目录的配置目录中的yml。
#7
0
Make sure mysql server is running.
确保mysql服务器正在运行。
#1
41
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.
我最大的猜测是,你提到的Windows机器已经启用了IPv6网络。因此,当您尝试进入localhost时,它将解析为“::1”。然而,这实际上是本地机器,默认的MySQL安装通常将绑定地址设置为127.0.0.1,这将导致localhost在此设置中失败。
You might be able to verify this by running ping localhost
from the command prompt, and seeing if you get a response like:
您可以通过从命令提示符运行ping localhost来验证这一点,并查看是否得到如下响应:
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.
或者,您可以更改MySQL的配置,以允许使用不同的绑定地址,例如localhost,而不是127.0.0.1。
#2
4
simply change your host to host:127.0.0.1
只需将主机更改为主机:127.0.0.1
#3
3
Change the value of host in the database.yml to be "127.0.0.1" will work. Or,you can modify your pc's hosts file, add an item as "localhost 127.0.0.1".
更改数据库中主机的值。yml设为“127.0.0.1”即可。或者,您可以修改您的pc主机文件,将一个项目添加为“localhost 127.0.0.1”。
#4
3
I had a similar error but it was because the port: 3306 was missing in the database.yml. Once I added port: 3306 issue was resolved.
我也有类似的错误,但那是因为数据库中缺少端口:3306。一旦我添加了port: 3306,问题就解决了。
#5
1
It's because you don't have password set in your database server(mysql), try this:
因为您的数据库服务器(mysql)没有设置密码,请尝试以下操作:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: bookmobile
pool: 5
username: macDaddy
password:
host: localhost
socket: mysql
port: 3306
#6
1
make sure the port number that you have set while creating MySQL(e.g.: 7777), please add port number with appropriate 'username' and 'password'.
确保创建MySQL时设置的端口号。: 7777),请加上“用户名”及“密码”的端口号。
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: admin
host: localhost
port: 7777
in the database.yml in config directory of your app directory.
在数据库中。在应用程序目录的配置目录中的yml。
#7
0
Make sure mysql server is running.
确保mysql服务器正在运行。