2012-07-15

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

Windows7マシンでRails環境を構築していたら嵌ったのでメモ コマンドプロンプトからは
mysql -uroot -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.25a MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
とちゃんと繋がってくれるのに、rakeコマンドで接続しようとすると
rake db:create
Can't connect to MySQL server on 'localhost' (10061)
Couldn't create database for ...
てな感じで怒られてしまい何がなんやら┐('~`;)┌
繋がらないって言ってるし、localhostが解決できていないのか!?
と思って、config/database.ymlのhost: localhostをhost: 127.0.0.1に変更してみると...
繋がった(・・;
でも、mysqlクラインとからは-h localhostとやっても繋がるという
とりあえずpingかけてみると
ping localhost
localhost [::1]に ping を送信しています 32 バイトのデータ:
::1 からの応答: 時間 <1ms
あれ、IP V6のループバックアドレスになってるっ!?
てことで、C:\Windows\System32\drivers\etc\hostsに
127.0.0.1       localhost
という記述を追加。再度pingしてみると
ping localhost
localhost [127.0.0.1]に ping を送信しています 32 バイトのデータ:
127.0.0.1 からの応答: バイト数 =32 時間 <1ms TTL=128
とIP V4のループバックアドレスが帰ってきてくれました。
この状態にしておけばhost: localhostでもrakeからMySQLに繋がりましたよヾ(*・∀・)ノ"

0 件のコメント:

コメントを投稿