zoukankan      html  css  js  c++  java
  • rails出现Can't connect to MySQL server on 'localhost' (10061)问题的解决方法

    rails3 跑在win7下面,装了mysql,cmd里面mysql -u 和telnet 都没问题,但是rails3 执行rake db:create的时候出现Can't connect to MySQL server on 'localhost' (10061)的错误

    后几经google,国外同行也有类似问题,问题描述的也比较清楚,原帖如下:
    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
     
    Any ideas how to fix this?
     
     
    asked Jan 18 at 19:52
     
     
    虽然老外也是很多驴头不对马嘴的情况,不过还是有靠谱的答案:
    大意是因为ipv6的原因导致的。
    两种解决之道
    1种是修改database.yml的配置host: 127.0.0.1
    另种是修改mysql.ini,修改或者增加bing-address
    bind-address=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.

    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.

    answered May 29 at 4:33
    772210
  • 相关阅读:
    Java第三方工具库/包汇总
    龙果开源支付系统介绍
    a标签href不跳转 禁止跳转
    使用LVS 实现负载均衡的原理。
    使用LVS实现负载均衡原理及安装配置详解
    这是一套Java菜鸟到大牛的学习路线之高级教程,由工作了10年的资深Java架构师整理。
    LoadRunner使用教程
    Mac OS启动服务优化高级篇(launchd tuning)禁用某些服务
    三种方式配置Mac OS X的启动项
    网络资源整理
  • 原文地址:https://www.cnblogs.com/linbirg/p/2600366.html
Copyright © 2011-2022 走看看