2015年2月20日金曜日

[MySQL]他ホストから接続させる方法

まずはPortの確認。デフォルトの3306。

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)


あれよこれよといじっても接続できない。
$ mysql -u xxx -p -h 10.X.X.X -P 3006
$ mysql -u xxx -p -h 10.X.X.X
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '10.X.X.X' (111) <- 適宜IP

重要なのがここ!定義ファイル!

sudo vi /etc/mysql/my.cnf
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1
bind-address            = 0.0.0.0

MySQL再起動!
$ sudo /etc/init.d/mysql restart


参考:http://atatte55.blog62.fc2.com/blog-entry-204.html