ponkiti's blog

主に自分用、イベント参加メモや備忘録として利用

MySQLサーバへの接続確認

ケース

  • 社内の検証サーバ上のDB(MySQLサーバ)に接続できない。(リプレイスに失敗していてDBがしんでいたり、サーバの設定変更により接続できないことがちょくちょく発生していて、DBの中身が見られないことがよくある・・・。)

経緯

  • DBIを利用したPerlプログラム実行時に下記のようなエラーメッセージが出力された。
  • 確認のためSequel ProからDBにアクセスしようとしたが、接続できなかった。
DBI connect('データベース名:サーバ名:ポート番号','ユーザ名',...) failed: Can't connect to MySQL server on 'サーバ名' (113) at dbi_connect.pl line 171.

対処

  • ブログラムに問題があるのか、サーバの障害によるものなのかを確認するため、コマンドラインMySQLサーバへの接続確認を行なう。
$ ping ホスト名
PING ホスト名 (ホスト名) 56(84) bytes of data.
64 bytes from ホスト名: icmp_seq=1 ttl=64 time=0.783 ms
(省略)

$ mysql -h ホスト名 -u ユーザ名 -p
ERROR 2003 (HY000): Can't connect to MySQL server on 'ホスト名' (113)

MySQLサーバへ接続できないことを確認した。プログラムに問題があるわけではないので、サーバ管理者へ連絡し、DBに接続できるようにしていただく。

解決

$ mysql -h ホスト名 -u ユーザ名 -p
elcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 46
Server version: 5.6.13-log MySQL Community Server (GPL)

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

参考