System Status
Buy Now
  • Email & Apps
  • Office 365
Login
  • MyRackspace Portal
  • Cloud Control Panel
  • Rackspace Webmail Login
  • Cloud Office Control Panel
  • Support Home
  • How-To
  • Developer Documentation
  •  Blogs 
    • Expert Insights Tech Blog
    • Rackspace Blog
    • Solve: Thought Leadership

Support Network

End-to-End Multicloud Solutions.   Solving Together.™   Learn more at Rackspace.com

How–To Home

Cloud Servers

  • Introduction
  • FAQ
  • All Articles

MySQL Java Database connectivity communications exception

Last updated on:  2021-03-03

Authored by:  Miguel Salgado


Java Database Connectivity (JDBC) is the Java API that allows you to access and execute queries and commands on a database.

This article describes some steps to troubleshoot the com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure error, which occurs when you try to connect to a database by using JDBC.

The Communications link failure error occurs when the database cannot be reached. Following are the possible causes and their solutions:

The IP address or hostname in JDBC URL is wrong.

Verify and test that the hostname or the IP address can answer back by using ping.

The local DNS server does not recognise the hostname in the JDBC URL

Refresh your DNS or use the IP address in JDBC URL instead.

The port number is missing or incorrect in JDBC URL

Verify that the IP is well configured in the MySQL® database my.cnf file by using your favorite text editor.

To find the my.cnf file, run the following command to check your MySQL settings:

mysql --help | grep "Default options" -A 1 

If you still can’t find the file, try running the following command:

find / -name my.cnf

You can also look in the default locations:

  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • /usr/etc/my.cnf
  • ~/.my.cnf

The database server is not accepting TCP/IP connections

Verify that the mysqld service is rrunning. To verify the status of the mysqld service, run the following commands according to your Linux® distribution:

For CentOS® 6 or Red Hat® Enterprise Linux® (RHEL) 6:

service mariadb status

For CentOS 7+ or RHEL 7+:

systemctl status mariadb.service

For the Ubuntu® operating system:

/etc/init.d/mysql status

The database is down or powered off

Run the following command to start the MySQL database:

For CentOS 6 / RHEL 6:

service mariadb start

For CentOS 7+ / RHEL 7+:

systemctl start mariadb.service

For the Ubuntu operating system:

/etc/init.d/mysql start

The database server has run out of connections

Restart the database and see if your code is having an issue when closing the connections.

Connections between Java and DB are blocking the communication

Disable the firewall or proxy. Alternately, configure them to allow or forward the port. If you are using CentOS 6/RHEL 6, review the iptables article.

Share this information:

©2020 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER

About Rackspace
  • About
  • Customer Stories
  • Events
  • Programs
Blogs
  • The Rackspace Blog
  • Expert Insights Tech Blog
  • Solve: Thought Leadership
  • News
  • Contact Information
  • Legal
  • Careers
Site Information
  • Style Guide for Technical Content
  • Trademarks
  • Privacy Statement
  • Website Terms
Support Network
  • Support Network Home
  • Rackspace How-To
  • API Documentation
  • Developer Center
  • ©2020 Rackspace US, Inc.