MySQL 4.1 (on Debian GNU/Linux Sarge) に Java 5_06 with Connector/J 3.1.12 (on Windows 2000) で接続したら、失敗。


Exception in thread "main" com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
 
** BEGIN NESTED EXCEPTION ** 
 
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
 
STACKTRACE:
 
java.net.SocketException: java.net.ConnectException: Connection refused: connect
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at Hoge.main(Hoge.java:39)
 
 
** END NESTED EXCEPTION **
 
 
 
Last packet sent to the server was 16 ms ago.
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2621)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at Hoge.main(Hoge.java:39)

あぁ、ぜんぜんわからない……

The problem could be the server configuration used by the Debian package. By default the Debian installation only accepts connections from localhost (127.0.0.1). Check the configuration file '/etc/mysql/my.cnf' for the line that looks like 'bind-address = 127.0.0.1'. Just comment this out to allow the server to accept remote connections. Of course you have to make sure a mysql account is created for the remote host as well.

MySQL AB :: MySQL Forums :: JDBC :: Re: cant' connect to mysql on debian linux. connector installed

bind-address が問題らしい。

> bind-address=127.0.0.1 #<< ここが問題でしょうか
> この bind-address をどうやって記述したらよいのか、
> あるいは別の設定があるのかご指導ください。

問題です。bind-address は、サーバが複数の IPアドレスを持っている場合に、
特定のアドレスでしか待ち受けないようにするという指定です。

なので、特に接続を制限したくないのであれば、コメントアウトすればいいと
思います。

mysql:9635

接続元の制限をしたいので、許可する接続元からしか見えないIPアドレスを指定して、と。

my.cnf の bind-address に


bind-address            = 192.168.0.88

みたいな設定で対処したら動いた。わーい。

MySQL 4.1 リファレンスマニュアル :: 4.1.1 mysqld コマンドラインオプション みても、よくわからんかった。「バインドする IP アドレス。」としか説明が無いからなぁ。

tags: zlashdot Database MySQL

Posted by NI-Lab. (@nilab)