Defect #11685

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

Added by Giovanni Junior over 2 years ago. Updated almost 2 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Documentation
Target version:-
Resolution:Invalid Affected version:

Description

I got the error "Can't connect to MySQL server on 'localhost' (10061)" when trying to execute migrations on my old Redmine database.

After lots of searching I found this page, who solved my problem: https://github.com/brianmario/mysql2/issues/157

The problem seems to be that Mysql2 adapter doesn't understand the hostname "localhost". To solve it, I had to replace "localhost" with "127.0.0.1" in database.yml.

I think the RedmineInstall guide should warn users to use "127.0.0.7" instead of "localhost" when using the Mysql2 adapter.

My configuration:
Windows 7 64 bits
MySQL 5.5 (or 5.1) 64 bits
MySQL Connector C 6.0.2 32 bits
Ruby 1.9.3 32 bits
Mysql2 gem, version 0.3.11

History

#1 Updated by Etienne Massip over 2 years ago

  • Category changed from Website (redmine.org) to Documentation
  • Status changed from New to Closed
  • Assignee deleted (Jean-Philippe Lang)
  • Priority changed from High to Normal
  • Resolution set to Invalid

Actually the problem seems to be that the "localhost" entry has been removed from your hosts file, probably by MS Windows Defender.

Sorry I close this issue as it is not a RM one, please reopen if you're absolutly sure that this is due to the mysql2 adapter unable to resolve localhost and provide a valid reference to the adapter issue.

#2 Updated by Giovanni Junior over 2 years ago

I didn't intend to point out a problem with Redmine itself. I just wanted to help you improve the documentation for users trying to install it, in order to keep the experience as painless as it had always been for me, and to prevent other users from wasting time as I did.

Even if what I described is not a legitimate "issue" of the mysql2 adapter, I still think it could be mentioned in the section of RedmineInstall dedicated specifically to Windows: http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Notes-on-Windows-installation

I'm not reopening this issue, as it's your responsibility to decide what deserves to be documented.

#3 Updated by Giovanni Junior over 2 years ago

One more interesting thing: the former mysql adapter works fine with "localhost" on the same environment, as well as other clients. The fact that I had this error only with the mysql2 adapter made the problem trickier.

#4 Updated by Etienne Massip over 2 years ago

Giovanni Junior wrote:

One more interesting thing: the former mysql adapter works fine with "localhost" on the same environment, as well as other clients. The fact that I had this error only with the mysql2 adapter made the problem trickier.

Did you have a localhost mapping in your hosts file?

#5 Updated by Giovanni Junior over 2 years ago

I read some instructions which mentioned the hosts file, but ignored them, as I never had to edit that file before and "127.0.0.1" was an easier (and less intrusive) solution.

Everything in my hosts file is commented out (I've never changed it).

#6 Updated by Etienne Massip over 2 years ago

Giovanni Junior wrote:

I read some instructions which mentioned the hosts file, but ignored them, as I never had to edit that file before and "127.0.0.1" was an easier (and less intrusive) solution.

Everything in my hosts file is commented out (I've never changed it).

Ok, googling a bit more, here's a different theory: by default, localhost is commented out in W7+ hosts file1 and IPV6 is the default2. As "mysql2 gem does no support IPV6 addresses3, connection won't be established.
Then I can only assume that mysql gem supports IPV6 adresses.

If you could confirm it (simply by pinging localhost), it might be worse to add a note in guide about this indeed.
BTW, Redmine guide is editable by everyone.

1 http://serverfault.com/questions/4689/windows-7-localhost-name-resolution-is-handled-within-dns-itself-why

2 http://www.victor-ratajczyk.com/post/2012/02/25/mysql-fails-to-resolve-localhost-disable-ipv6-on-windows.aspx

3 https://github.com/brianmario/mysql2/issues/279

#7 Updated by Giovanni Junior over 2 years ago

Ping localhost targets "::1:", meaning IPV6 is being used.

I can't see any icons or links to edit wiki pages...

#8 Updated by Martin Dubé about 2 years ago

  • Status changed from Closed to Reopened

I just bang my head for hours trying to figure why I was getting error 10061 with mysql2 on Windows 7 and it turns out the solution was to replace localhost by 127.0.0.1 in database.yml.

I neither can't find how to edit the wiki to add a note about this, so I reopen the issue hoping someone will edit the wiki.

#9 Updated by Jan Niggemann (redmine.org team member) almost 2 years ago

  • Status changed from Reopened to Resolved

Etienne Massip wrote:

BTW, Redmine guide is editable by everyone.

Not exactly, the page RedmineInstall is locked.

I added the relevant information for Win7+ users from this issue to the wiki page.

#10 Updated by Jan Niggemann (redmine.org team member) almost 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF