ボールを蹴りたいシステムエンジニア

ボール蹴りが大好きなシステムエンジニア、ボールを蹴る時間確保の為に時間がある時には勉強する。

cygwinからmysql接続のエラー、ip指定で解決

windowscygwinでのmysql利用メモ

windowsmysql使うときGUIMySQL Workbenchを使っているのですが、たまにCUIで操作したくなります。
ですがwindowsコマンドプロンプトは使いづらく、cygwinmysqlを利用する事に。

まずは、cygwinのsetup.exeでmysqlのパッケージをインストール。
そしてmysql実行

$ mysql -u root -p                                                                                                
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)

入れない・・

で、調べてみると、windowsのcygwindでのmysqlログイン時はホストをIPで指定しないと駄目らしい。
こんな感じ

$ mysql -u root -p -h 127.0.0.1                                                                                    
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.41-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> 

入れた

localhost」では駄目らしい

$ mysql -u root -p -h localhost                                                                                    
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)

下記の参考サイトよると、
localhost指定だと暗黙的にソケットが使用されるけどWindowsにはそんなのないからだとか。

…よく分からないけど、とりあえずWindowscygwinmysql実行時は-hでipを指定するように。