JDBC Connector Communication link failure error to MySQL

By Dillon Smart · · · 1 Comments

DBeaver SQL Client

Are you having trouble connecting to a MySQL database through JDBC Connector in a database management tool such as DBeaver Community Edition?

DBeaver fails to connect to a local MySQL database with the error “Communication link failure the last packet sent successfully to the server was 0 milliseconds ago“.

Here is a breakdown of this page:

Introduction

The problem isn’t with DBeaver. If you install another MySQL GUI tool, this issue will still occur.

This error occurs when the port used by MySQL is busy. To fix the communication link failure in DBeaver, we need to assign a port to MySQL.

In the solution below I used a Linux machine running Ubuntu 20.04 and verified using a Windows machine running Ubuntu 18.04 through WSL2 (Windows Subsystem for Linux).

Where possible I have provided alternative methods for both macOS and Windows.

This post also assumes you already have the correct database drivers installed and have created the MySQL connection.

DBeaver Communication Link Failure

Solution – Fixing communication link failure in DBeaver

First, you will need to locate your my.cnf file.

The my.cnf file is the configuration file used by MySQL. This MYSQL configuration file can reside in different locations, depending on your system and how it was installed.

Below are some locations where your installation’s my.conf could be for different operating systems.

Location of MySQL my.cnf file on MacOS or Linux

On macOS and Linux, you can find the MySQL configuration file in either the users home directory or within the /etc directory.

  • ~/.my.cnf
  • /etc/my.cnf

Location of MySQL my.cnf file on Windows

On a Windows machine, the MySQL configuration file can be in either the Windows directory or the root of the C drive.

In some cases, the my.cnf file can actually be a ini file, like so:

  • C:\Windows\my.ini
  • C:\Windows\my.cnf
  • C:\my.ini
  • C:\my.cnf

Once you have located the file, open it with your preferred editor. I will be using Nano.

nano /etc/mysql/my.cnf

You may need to append sudo to the command if you require higher security privileges.

Edit MySQL cnf file

Once you have opened the file using an editor, go to the bottom of the file and add the following configuration:

[mysqld]
port=3306 # or any other port
bind-address=0.0.0.0

Set the port to a port you know is open and not in use. By default, MySQL uses port 3306, but you can change this to another open port if required.

Save the file using Ctrl+O.

Now restart MySQL, there are multiple ways to do this, depending on your environment.

Restart MySQL on macOS or Linux

/etc/init.d/mysqld restart
# or 
systemctl restart mysqld

Restart MySQL on Windows

  • Open ‘Run’ by using Win key + R
  • Type ‘services.msc’
  • Now search for MySQL based on the version that is installed.
  • Click on ‘restart

If you found this post useful, check out how to Create SSH Connections in DBeaver.

Did this solution work for you? Leave a comment with your results.

DBeaverMySQL

1 Comment

A.

Only resolution that helped. Many articles talk about the Bind-Address, and setting the MySQL user with host = "%", but none I came across besides this one mentioned adding the port to the my.cnf file. Great job on that. Consolidated Resolutions 0. Start the mysql service. a. Some installations call the service "mysqld" so the command to start it may be sudo service mysqld start. 1. MySQL user needs host = % and proper privileges on the database. 2. My.cnf file needs bind-address = 0.0.0.0 or can comment this line out entirely if one exists in the file to allow all interfaces. 3. My.cnf file absolutely requires the port=3306 entry or you'll get connection refused. a. Restart the mysql service on the server after updating the my.cnf. 4. Whatever firewall is installed on the server needs to allow port 3306 to listen for traffic or no matter what else you're doing you won't be able to access the database. a. Restart the firewall after making any updates. 5. Ensure that the username entered into your database connection string is case appropriate, or you'll get user denial even with correct username/password -- the username is case sensitive in MySQL. Example with Dbeaver where the user was alphanumeric and the first two characters are alpha, the remainder numeric, was getting auth failures for the user credentials until changing the case to what was stored in mysql.

Was this helpful? Leave a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to grant full privileges to a user in MySQL

Updated 16th August 2022

After setting up a lamp stack development environement with phpmyadmin locally on Linux you may notice that your phpmyadmin user (or other user name) doesn’t have the correct privileges to create new databases. To use the phpmyadmin user to create new databases and users for those databases you need to grant full privileges to the

The ULTIMATE guide to setup Windows Subsystem for Linux (WSL) with Ubuntu, Apache2, MySQL and PHP

Updated 16th August 2022

Windows is now good for development! Yes! All thanks to Windows Subsystem for Linux (WSL). No more WAMP or Xampp, WSL can do everything you need. In this ultimate guide to setup Windows Subsystem for Linux with Ubuntu, Apache2, MySQL, and PHP we will cover: What is Windows Subsystem for Linux? Setting up Windows Subsystem

Create SSH Connections in DBeaver

Updated 16th August 2022

In this post, I will show you step-by-step how to Create SSH Connections in DBeaver. Create SSH Connections in DBeaver First, select the Create New Connection option found in the top right. This will open a window to select the database driver. In this example, I will be creating an SSH connection to a MySQL