【MySQL/DBeaver】
MySQL接続時に「Connection refused Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server Connection refused Connection refused」が発生した際の解消方法

MySQLが起動しなくなった際の対処

投稿日 2024/03/12 更新日 2024/03/12


こんにちは。IT業界歴4年目の「元木皇天」です。

今回はDBeaverからMySQLサーバに接続しようとした際にエラー、「Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Connection refused Connection refused」が発生した場合の対処方法について解説いたします。

やりたいこと

DBeaverからMySQLへの接続時に発生したエラーを解消し、接続できるようにする


環境

・OS:MacOS Sonoma 14.3.1
・MySQL:Ver 8.3.0
・DBeaver:24.0.0.202403091004

原因

エラーが発生する原因は人それぞれだと思いますが、私の場合はMySQLサーバが起動できていなかったことが原因でした。

自分では起動した気になっていたのですが、改めて確認すると起動時にエラーが発生しており、起動に失敗しているようでした。

なので、今回のエラーの根本的な原因はMySQLサーバが起動できていないということになります。


次に、MySQLサーバが起動できていない原因を確認します。

以下のパスにMySQLサーバ起動時のエラーログが残っているので、こちらをlessコマンドで開き中身を確認します。

cd /usr/local/var/mysql
less {ホスト名}.local.err

※{ホスト名}には人それぞれ異なる値が入ります。


私の場合は以下のエラーが出力されていました。

2024-03-11T13:15:00.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
dyld[20963]: Library not loaded: /usr/local/opt/icu4c/lib/libicuuc.72.dylib
Referenced from:  /usr/local/Cellar/mysql/8.0.33/bin/mysqld
Reason: tried: '/usr/local/opt/icu4c/lib/libicuuc.72.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/icu4c/lib/libicuuc.72.dylib' (no such file), '/usr/local/opt/icu4c/lib/libicuuc.72.dylib' (no such file), '/usr/local/lib/libicuuc.72.dylib' (no such file), '/usr/lib/libicuuc.72.dylib' (no such file, not in dyld cache), '/usr/local/Cellar/icu4c/73.2/lib/libicuuc.72.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/Cellar/icu4c/73.2/lib/libicuuc.72.dylib' (no such file), '/usr/local/Cellar/icu4c/73.2/lib/libicuuc.72.dylib' (no such file), '/usr/local/lib/libicuuc.72.dylib' (no such file), '/usr/lib/libicuuc.72.dylib' (no such file, not in dyld cache)

どうやらicu4cというライブラリがないためエラーが起きているようです。

解消方法

icu4cというライブラリが存在していないので、こちらをインストールします。

ネットで調べるとhomebrewを使用してインストールできるようなので、以下コマンドで該当のライブラリをインストールしました。

brew install icu4c

その後、MySQLを起動するコマンドを実行したら正常に起動し、今回の発端となったエラー「Connection refused Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server Connection refused Connection refused」も無事解消されました。

MySQLサーバが起動した画像

まとめ

MySQL関連でエラーが発生したな場合は、/usr/local/var/mysql配下のエラーログを確認しましょう。

参考文献・おすすめ文献