Help us understand the problem. What is going on with this article?

「Communications link failure」が出る時

More than 1 year has passed since last update.

MySQLのポート番号を調べる

MySQLのListenしているポートを調べます。

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3307  |
+---------------+-------+

以下のコマンドでポート確認できているつもりになっていると、ハマる場合があります。
実際にはmysql.sockが使われている場合があります。

確認コマンド
$ mysql -uroot -hlocalhost -P3306 -p

シェルコマンドで確認する場合は、telnetで行うのが確実です。

MySQLのコネクションタイムアウト値を調べる

MySQLのコネクションタイムアウト値が短すぎると、JDBCのコネクションプール機能を使用している時にエラーが出る場合があります。

以下のコマンドで、コネクションタイムアウト値wait_timeoutが短すぎないか確認します。

show global variables like '%wait%';
+---------------------------------------------------+----------+
| Variable_name                                     | Value    |
+---------------------------------------------------+----------+
| innodb_lock_wait_timeout                          | 120      |
| innodb_spin_wait_delay                            | 6        |
| lock_wait_timeout                                 | 31536000 |
| performance_schema_events_waits_history_long_size | 10000    |
| performance_schema_events_waits_history_size      | 10       |
| wait_timeout                                      | 60       |
+---------------------------------------------------+----------+

確実に接続したい場合は、default.poolValidationQueryを設定して、接続確認を行うようにします。

default.poolValidationQuery="select 1 as one"

■参考
scalikejdbcでmysqlとの通信時のCommunicationsExceptionに対処する
http://zudoh.com/archives/248

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away