Rails development - Can't connect to MySQL server on 'localhost' (10061)

眉间皱痕 提交于 2019-11-30 06:48:22

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.

simply change your host to host:127.0.0.1

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".

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.

It's because you don't have password set in your database server(mysql), try this:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: bookmobile
  pool: 5
  username: macDaddy
  password:
  host: localhost
  socket: mysql
  port: 3306

make sure the port number that you have set while creating MySQL(e.g.: 7777), please add port number with appropriate 'username' and 'password'.

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.

Make sure mysql server is running.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!