<link href='https://www.blogger.com/dyn-css/authorization.css?targetBlogID=6388623008298669567&amp;zx=77caa444-546b-4dc9-a502-9f5270da3194' rel='stylesheet'/>

2014年7月24日木曜日

[MySQL] 外部から接続するのに失敗しまくった(ファイアウォール、my.cnf、権限)

LinuxにインストールしたMySQLに外部から接続するのに何度も失敗して結構時間食った。

ファイアウォールでやらかす

まず最初のエラー。下記コマンドを試みる。
外部から接続するコマンド
1
2
C:\Users\>mysql -u <MySQLのユーザ> -h '<DBサーバIP>' -p
Enter password: *********
すると、
1
ERROR 2003 (HY000): Can't connect to MySQL server on '<クライアントIP>' (10060)
"Can't connect to MySQL server" でググった結果、DBサーバのファイアウォールの設定では?とのこと。
1
iptables -L
して設定状況を確認する。
INPUTチェインでREJECTしているルールがあったので削除。
(本来はダメだろうけど、とりあえず問題を切り分ける為に実施)

my.cnf でやらかす

再度接続を試みると、
1
ERROR 1042 (HY000): Can't get hostname for your address
またググる。
MySQLの設定ファイル my.cnf に下記を追加すれば良いらしい。
1
skip-name-resolve
↓の通り追加した。
1
2
3
4
[mysqld]
(略)
skip-name-resolve
(略)

権限でやらかす

再度接続を試みると、
1
ERROR 1130 (HY000): Host '<クライアントIP>' is not allowed to connect to this MySQL server
またググる。
ログインを試みているユーザに、クライアントPCからアクセスする権限を付与しないといけないらしい。
1
GRANT ALL PRIVILEGES ON *.* TO <MySQLユーザ>@'<クライアントIP>' IDENTIFIED BY '<パスワード>' WITH GRANT OPTION;
実際はデータベースやテーブルをちゃんと指定する必要あり。。 これでようやく…
1
2
3
4
5
6
7
8
9
10
11
12
13
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.10 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>

【参考】

MySQLで外部から接続するときにチェックする項目 - yummy-yummy
MySQL を外部接続できるようにする - 怠惰な日々
Linuxコマンド集 - 【iptables】パケットフィルタリングを設定する:ITpro

0 件のコメント:

コメントを投稿