Solving a “communications link failure” with JDBC and MySQL [duplicate]












172
















This question already has an answer here:




  • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    33 answers




I'm trying to connect to the local MySQL server but I keep getting an error.



Here is the code.



public class Connect {

public static void main(String args) {
Connection conn = null;

try {
String userName = "myUsername";
String password = "myPassword";

String url = "jdbc:mysql://localhost:3306/myDatabaseName";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Database connection established");
} catch (Exception e) {
System.err.println("Cannot connect to database server");
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
System.out.println("Database Connection Terminated");
} catch (Exception e) {}
}
}
}
}


and the errors :



Cannot connect to database server
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.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Connect.main(Connect.java:16)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 15 more


I've set the classpath, made sure my.cnf had the skip network option commented out.



java version is 1.2.0_26 (64 bit)
mysql 5.5.14
mysql connector 5.1.17



I made sure that the user had access to my database.










share|improve this question















marked as duplicate by BalusC java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jul 27 '16 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 4





    Note the CausedBy at the bottom. The SQL server never accepted the connection. What happens if do (from a command line) telnet localhost 3306? Is the mySQL server running?

    – Jim Garrison
    Jul 28 '11 at 20:59













  • Check this post. Might help: stackoverflow.com/questions/15949/…

    – Matt MacLean
    Jul 28 '11 at 21:07






  • 1





    Problem solved, added a bind-address entry to my.cnf.

    – Anthony
    Jul 28 '11 at 21:28






  • 3





    @Anthony You should put your comment as an answer and accept it ...

    – Fildor
    Nov 1 '11 at 17:24






  • 1





    I tried going to Windows Services in Control Panel and started mysql service and then it worked..try this solution

    – tinku
    Mar 6 '13 at 7:29
















172
















This question already has an answer here:




  • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    33 answers




I'm trying to connect to the local MySQL server but I keep getting an error.



Here is the code.



public class Connect {

public static void main(String args) {
Connection conn = null;

try {
String userName = "myUsername";
String password = "myPassword";

String url = "jdbc:mysql://localhost:3306/myDatabaseName";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Database connection established");
} catch (Exception e) {
System.err.println("Cannot connect to database server");
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
System.out.println("Database Connection Terminated");
} catch (Exception e) {}
}
}
}
}


and the errors :



Cannot connect to database server
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.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Connect.main(Connect.java:16)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 15 more


I've set the classpath, made sure my.cnf had the skip network option commented out.



java version is 1.2.0_26 (64 bit)
mysql 5.5.14
mysql connector 5.1.17



I made sure that the user had access to my database.










share|improve this question















marked as duplicate by BalusC java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jul 27 '16 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 4





    Note the CausedBy at the bottom. The SQL server never accepted the connection. What happens if do (from a command line) telnet localhost 3306? Is the mySQL server running?

    – Jim Garrison
    Jul 28 '11 at 20:59













  • Check this post. Might help: stackoverflow.com/questions/15949/…

    – Matt MacLean
    Jul 28 '11 at 21:07






  • 1





    Problem solved, added a bind-address entry to my.cnf.

    – Anthony
    Jul 28 '11 at 21:28






  • 3





    @Anthony You should put your comment as an answer and accept it ...

    – Fildor
    Nov 1 '11 at 17:24






  • 1





    I tried going to Windows Services in Control Panel and started mysql service and then it worked..try this solution

    – tinku
    Mar 6 '13 at 7:29














172












172








172


116







This question already has an answer here:




  • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    33 answers




I'm trying to connect to the local MySQL server but I keep getting an error.



Here is the code.



public class Connect {

public static void main(String args) {
Connection conn = null;

try {
String userName = "myUsername";
String password = "myPassword";

String url = "jdbc:mysql://localhost:3306/myDatabaseName";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Database connection established");
} catch (Exception e) {
System.err.println("Cannot connect to database server");
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
System.out.println("Database Connection Terminated");
} catch (Exception e) {}
}
}
}
}


and the errors :



Cannot connect to database server
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.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Connect.main(Connect.java:16)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 15 more


I've set the classpath, made sure my.cnf had the skip network option commented out.



java version is 1.2.0_26 (64 bit)
mysql 5.5.14
mysql connector 5.1.17



I made sure that the user had access to my database.










share|improve this question

















This question already has an answer here:




  • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    33 answers




I'm trying to connect to the local MySQL server but I keep getting an error.



Here is the code.



public class Connect {

public static void main(String args) {
Connection conn = null;

try {
String userName = "myUsername";
String password = "myPassword";

String url = "jdbc:mysql://localhost:3306/myDatabaseName";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Database connection established");
} catch (Exception e) {
System.err.println("Cannot connect to database server");
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
System.out.println("Database Connection Terminated");
} catch (Exception e) {}
}
}
}
}


and the errors :



Cannot connect to database server
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.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Connect.main(Connect.java:16)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 15 more


I've set the classpath, made sure my.cnf had the skip network option commented out.



java version is 1.2.0_26 (64 bit)
mysql 5.5.14
mysql connector 5.1.17



I made sure that the user had access to my database.





This question already has an answer here:




  • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    33 answers








java mysql jdbc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 18 '14 at 15:53









Tiny

8,70178258500




8,70178258500










asked Jul 28 '11 at 20:55









AnthonyAnthony

888389




888389




marked as duplicate by BalusC java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jul 27 '16 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by BalusC java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jul 27 '16 at 6:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 4





    Note the CausedBy at the bottom. The SQL server never accepted the connection. What happens if do (from a command line) telnet localhost 3306? Is the mySQL server running?

    – Jim Garrison
    Jul 28 '11 at 20:59













  • Check this post. Might help: stackoverflow.com/questions/15949/…

    – Matt MacLean
    Jul 28 '11 at 21:07






  • 1





    Problem solved, added a bind-address entry to my.cnf.

    – Anthony
    Jul 28 '11 at 21:28






  • 3





    @Anthony You should put your comment as an answer and accept it ...

    – Fildor
    Nov 1 '11 at 17:24






  • 1





    I tried going to Windows Services in Control Panel and started mysql service and then it worked..try this solution

    – tinku
    Mar 6 '13 at 7:29














  • 4





    Note the CausedBy at the bottom. The SQL server never accepted the connection. What happens if do (from a command line) telnet localhost 3306? Is the mySQL server running?

    – Jim Garrison
    Jul 28 '11 at 20:59













  • Check this post. Might help: stackoverflow.com/questions/15949/…

    – Matt MacLean
    Jul 28 '11 at 21:07






  • 1





    Problem solved, added a bind-address entry to my.cnf.

    – Anthony
    Jul 28 '11 at 21:28






  • 3





    @Anthony You should put your comment as an answer and accept it ...

    – Fildor
    Nov 1 '11 at 17:24






  • 1





    I tried going to Windows Services in Control Panel and started mysql service and then it worked..try this solution

    – tinku
    Mar 6 '13 at 7:29








4




4





Note the CausedBy at the bottom. The SQL server never accepted the connection. What happens if do (from a command line) telnet localhost 3306? Is the mySQL server running?

– Jim Garrison
Jul 28 '11 at 20:59







Note the CausedBy at the bottom. The SQL server never accepted the connection. What happens if do (from a command line) telnet localhost 3306? Is the mySQL server running?

– Jim Garrison
Jul 28 '11 at 20:59















Check this post. Might help: stackoverflow.com/questions/15949/…

– Matt MacLean
Jul 28 '11 at 21:07





Check this post. Might help: stackoverflow.com/questions/15949/…

– Matt MacLean
Jul 28 '11 at 21:07




1




1





Problem solved, added a bind-address entry to my.cnf.

– Anthony
Jul 28 '11 at 21:28





Problem solved, added a bind-address entry to my.cnf.

– Anthony
Jul 28 '11 at 21:28




3




3





@Anthony You should put your comment as an answer and accept it ...

– Fildor
Nov 1 '11 at 17:24





@Anthony You should put your comment as an answer and accept it ...

– Fildor
Nov 1 '11 at 17:24




1




1





I tried going to Windows Services in Control Panel and started mysql service and then it worked..try this solution

– tinku
Mar 6 '13 at 7:29





I tried going to Windows Services in Control Panel and started mysql service and then it worked..try this solution

– tinku
Mar 6 '13 at 7:29












25 Answers
25






active

oldest

votes


















339














I have had the same problem in two of my programs. My error was this:



com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.


I spent several days to solve this problem. I have tested many approaches that have been mentioned in different web sites, but non of them worked. Finally I changed my code and found out what was the problem. I'll try to tell you about different approaches and sum them up here.



While I was seeking the internet to find the solution for this error, I figured out that there are many solutions that worked for at least one person, but others say that it doesn't work for them! why there are many approaches to this error?
It seems this error can occur generally when there is a problem in connecting to the server. Maybe the problem is because of the wrong query string or too many connections to the database.



So I suggest you to try all the solutions one by one and don't give up!



Here are the solutions that I found on the internet and for each of them, there is at least on person who his problem has been solved with that solution.



Tip: For the solutions that you need to change the MySQL settings, you can refer to the following files:




  • Linux: /etc/mysql/my.cnf or /etc/my.cnf (depending on the Linux distribution and MySQL package used)


  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini (Notice it's ProgramData, not Program Files)



Here are the solutions:




  • changing "bind-address" attribute


Uncomment "bind-address" attribute or change it to one of the following IPs:



bind-address="127.0.0.1"



or



bind-address="0.0.0.0"




  • commenting out "skip-networking"


If there is a "skip-networking" line in your MySQL config file, make it comment by adding "#" sign at the beginning of that line.




  • change "wait_timeout" and "interactive_timeout"


Add these lines to the MySQL config file:



wait_timeout = number



interactive_timeout = number



connect_timeout = number





  • Make sure Java isn't translating 'localhost' to [:::1] instead of [127.0.0.1]


Since MySQL recognizes 127.0.0.1 (IPv4) but not :::1 (IPv6)



This could be avoided by using one of two approaches:



Option #1: In the connection string use 127.0.0.1 instead of localhost to avoid localhost being translated to :::1



Option #2: Run java with the option -Djava.net.preferIPv4Stack=true to force java to use IPv4 instead of IPv6. On Linux, this could also be achieved by running (or placing it inside /etc/profile:



export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"



  • check Operating System proxy settings, firewalls and anti-virus programs


Make sure the Firewall, or Anti-virus software isn't blocking MySQL service.



Stop iptables temporarily on linux. If iptables are misconfigured they may allow tcp packets to be sent to mysql port, but block tcp packets from coming back on the same connection.



# Redhat enterprise and CentOS
systemctl stop iptables.service
# Other linux distros
service iptables stop


Stop anti-virus software on Windows.




  • change connection string


Check your query string. your connection string should be some thing like this:



dbName = "my_database";
dbUserName = "root";
dbPassword = "";
String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";


Make sure you don't have spaces in your string. All the connection string should be continues without any space characters.



Try to replace "localhost" with the loopback address 127.0.0.1.
Also try to add port number to your connection string, like:



String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";


Usually default port for MySQL is 3306.



Don't forget to change username and password to the username and password of your MySQL server.




  • update your JDK driver library file

  • test different JDK and JREs (like JDK 6 and 7)

  • don't change max_allowed_packet


"max_allowed_packet" is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.




  • change tomcat security


change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no




  • use validationQuery property


use validationQuery="select now()" to make sure each query has responses




  • AutoReconnect


Add this code to your connection string:



&autoReconnect=true&failOverReadOnly=false&maxReconnects=10




Although non of these solutions worked for me, I suggest you to try them. Because there are some people who solved their problem with following these steps.



But what solved my problem?



My problem was that I had many SELECTs on database. Each time I was creating a connection and then closing it. Although I was closing the connection every time, but the system faced with many connections and gave me that error. What I did was that I defined my connection variable as a public (or private) variable for whole class and initialized it in the constructor. Then every time I just used that connection. It solved my problem and also increased my speed dramatically.



Conclusion



There is no simple and unique way to solve this problem. I suggest you to think about your own situation and choose above solutions. If you take this error at the beginning of the program and you are not able to connect to the database at all, you might have problem in your connection string. But If you take this error after several successful interaction to the database, the problem might be with number of connections and you may think about changing "wait_timeout" and other MySQL settings or rewrite your code how that reduce number of connections.






share|improve this answer





















  • 2





    I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

    – Siddharth
    Apr 4 '13 at 22:06






  • 1





    @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

    – smonff
    Mar 23 '15 at 10:25






  • 2





    @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

    – Basil Musa
    Feb 7 '16 at 18:30






  • 1





    @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

    – thorinkor
    May 17 '16 at 10:34






  • 1





    After using the correct transaction manager things are really fast. Thanks.

    – Markus Barthlen
    Sep 15 '16 at 11:34



















12














If you are using MAMP PRO, the easy fix, which I really wish I had realized before I started searching the internet for days trying to figure this out. Its really this simple...



You just have to click "Allow Network Access to MySQL" from the MAMP MySQL tab.



Really, thats it.



Oh, and you MIGHT have to still change your bind address to either 0.0.0.0 or 127.0.0.1 like outlined in the posts above, but clicking that box alone will probably solve your problems if you are a MAMP user.






share|improve this answer
























  • Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

    – Shantanu
    Jul 30 '15 at 8:45











  • For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

    – Strainy
    Jan 10 '16 at 20:23











  • My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

    – kimbaudi
    Jan 10 '17 at 20:21



















5














Setting the bind-address to the server's network IP instead of the localhost default, and setting privileges on my user worked for me.



my.cnf:



bind-address = 192.168.123.456


MySql Console:



GRANT ALL PRIVILEGES ON dbname.* to username@'%' IDENTIFIED BY 'password';





share|improve this answer



















  • 1





    Or use 0.0.0.0 for all interfaces...

    – Eric Kramer
    Jan 21 '16 at 19:14











  • answer worked for me, can you describe what does @'%' means in above mysql directive?

    – alex
    Sep 26 '16 at 5:27













  • bind-address = 0.0.0.0 worked for me.

    – Daddy32
    Aug 2 '17 at 11:54



















4














In my case,




  1. Change the remote machine mysql configuration at /etc/mysql/my.cnf: change
    bind-address = 127.0.0.1
    to
    #bind-address = 127.0.0.1


  2. On the remote machine, change mysql user permissions with
    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';


  3. IMPORTANT: restart mysql on the remote machine: sudo /etc/init.d/mysql restart







share|improve this answer
























  • After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

    – Luis Crespo
    May 7 '18 at 14:26



















3














As the detailed answer above says, this error can be caused by many things.



I had this problem too. My setup was Mac OSX 10.8, using a Vagrant managed VirtualBox VM of Ubuntu 12.04, with MySQL 5.5.34.



I had correctly setup port forwarding in the Vagrant config file. I could telnet to the MySQL instance both from my Mac and from within the VM. So I knew the MySQL daemon was running and reachable. But when I tried to connect over JDBC, I got the "Communications link failure" error.



In my case, the problem was solved by editing the /etc/mysql/my.cnf file. Specifically, I commented out the "#bind-address=127.0.0.1" line.






share|improve this answer
























  • Where did you change this? Host or Vagrant MySql?

    – Joe
    Mar 28 '18 at 4:48











  • I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

    – devdanke
    Apr 11 '18 at 4:14



















3














I've just faced the same problem.
It happened because the MySQL Daemon was binded to the IP of the machine, which is required to make connection with an user that has permission to connect @your_machine.
In this case, the user should have permission to connect USER_NAME@MACHINE_NAME_OR_IP



I wanted remote access to my machine so I changed in my.cnf from



bind-address = MY_IP_ADDRESS


To



bind-address = 0.0.0.0


Which will allow an user from localhost AND even outside (in my case) to connect to the instance.
Both below permissions will work if you bind the MySQL to 0.0.0.0:



USER_NAME@MACHINE_NAME_OR_IP

USER_NAME@localhost





share|improve this answer

































    2














    In my case it was an idle timeout, that caused the connection to be dropped on the server. The connection was kept open, but not used for a long period of time. Then a client restart works, while I believe a reconnect will work as well.



    A not bad solution is to have a daemon/service to ping the connection from time to time.






    share|improve this answer

































      2














      In my case (I am a noob), I was testing Servlet that make database connection with MySQL and one of the Exception is the one mentioned above.



      It made my head swing for some seconds but I came to realize that it was because I have not started my MySQL server in localhost.

      After starting the server, the problem was fixed.



      So, check whether MySQL server is running properly.






      share|improve this answer































        1














        For me the solution was to change in the conf file of mysql server the parameter bind-address="127.0.0.1" or bind-address="x.x.x.x" to bind-address="0.0.0.0".
        Thanks.






        share|improve this answer































          1














          In case you are having problem with a set of Docker containers, then make sure that you do not only EXPOSE the port 3306, but as well map the port from outside the container -p 3306:3306. For docker-compose.yml:



          version: '2'

          services:
          mdb:
          image: mariadb:10.1
          ports:
          - "3306:3306"






          share|improve this answer



















          • 2





            relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

            – chris.currin
            Nov 15 '17 at 9:09






          • 2





            Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

            – prayagupd
            Jun 26 '18 at 6:19





















          0














          It happens (in my case) when there is not enough memory for MySQL. A restart fixes it, but if that's the case consider a nachine with more memory, or limit the memory taken by jvms






          share|improve this answer
























          • Limiting the memory or just getting more memory seems like a temporary solution does it not?

            – Kerem
            Mar 18 '15 at 2:39



















          0














          Go to Windows services in the control panel and start the MySQL service. For me it worked. When I was doing a Java EE project I got this error" Communication link failure". I restarted my system and then it worked.



          After that I again got the same error even after restarting my system. Then I tried to open the MySQL command line console and login with root, even then it gave me an error.



          Finally when I started the MySQL service from Windows services, it worked.






          share|improve this answer

































            0














            Had the same.
            Removing port helped in my case, so I left it as jdbc:mysql://localhost/






            share|improve this answer































              0














              If you are using hibernate, this error can be caused for keeping open a Session object more time than wait_timeout



              I've documented a case in here for those who are interested.






              share|improve this answer































                0














                I found the solution



                since MySQL need the Localhost in-order to work.



                go to /etc/network/interfaces file and make sure you have the localhost configuration set there:



                auto lo
                iface lo inet loopback


                NOW RESTART the Networking subsystem and the MySQL Services:



                sudo /etc/init.d/networking restart



                sudo /etc/init.d/mysql restart



                Try it now






                share|improve this answer
























                • doesn't work on Mac

                  – Meetai.com
                  Jun 29 '14 at 9:57











                • not sure about Mac, this worked for me on Linux Debian.

                  – Mahmoud Zalt
                  Jun 30 '14 at 14:51






                • 1





                  Ok. This worked after changing MySQL port and connecting to that new port.

                  – Meetai.com
                  Jul 1 '14 at 0:26



















                0














                It is majorly because of weak connection between mysql client and remote mysql server.



                In my case it is because of flaky VPN connection.






                share|improve this answer































                  0














                  In phpstorm + vagrant autoReconnect driver option helped.






                  share|improve this answer
























                  • got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                    – Meetai.com
                    Jun 29 '14 at 9:57



















                  0














                  The resolution provided by Soheil was successful in my case.



                  To clarify, the only change I needed to make was with MySQL's server configuration;



                  bind-address = **INSERT-IP-HERE**


                  I am using an external MySQL server for my application. It is a basic Debian 7.5 installation with MySQL Server 5.5 - default configuration.



                  IMPORTANT:




                  Always backup the original of any configuration files you may modify. Always take care when elevated as super user.




                  File



                  /etc/mysql/my.cnf


                  Line



                  bind-address        = 192.168.0.103 #127.0.0.1


                  Restart your MySQL Server service:



                  /usr/sbin/service mysql restart


                  As you can see, I simply provided the network IP of the server and commented out the default entry. Please note that simply copy and paste my solution will not work for you, unless by some miracle our hosts share the same IP.



                  Thanks @ Soheil






                  share|improve this answer































                    0














                    I was experiencing similar problem and the solution for my case was




                    1. changing bind-address = 0.0.0.0 from 127.0.0.1

                    2. changing url's localhost to localhost:3306


                    the thing i felt is we should never give up, i tried every options from this post and from other forums as well...happy it works @saurab






                    share|improve this answer































                      0














                      I faced this problem also.



                      As Soheil suggested,
                      I went to php.ini file at the path C:windowsphp.ini , then I revised port number in this file.



                      it is on the line mysqli.default_port =..........



                      So I changed it in my java app as it's in the php.ini file,now it works fine with me.






                      share|improve this answer































                        0














                        I know this is an old thread but I have tried numerous things and fixed my issue using the following means..



                        I'm developing a cross platform app on Windows but to be used on Linux and Windows servers.



                        A MySQL database called "jtm" installed on both systems. For some reason, in my code I had the database name as "JTM". On Windows it worked fine, in fact on several Windows systems it flew along.



                        On Ubuntu I got the error above time and time again. I tested it out with the correct case in the code "jtm" and it works a treat.



                        Linux is obviously a lot less forgiving about case sensitivity (rightly so), whereas Windows makes allowances.



                        I feel a bit daft now but check everything. The error message is not the best but it does seem fixable if you persevere and get things right.






                        share|improve this answer































                          0














                          I just restarted MySQL (following a tip from here: https://stackoverflow.com/a/14238800) and it solved the issue.



                          I had the same issue on MacOS (10.10.2) and MySql (5.6.21) installed via homebrew.



                          The confusing thing was that one of my apps connected to the database fine and the other did not.



                          After trying many things on the app that threw the exception com.mysql.jdbc.CommunicationsException as suggested by the the accepted answer of this question to no avail, I was surprised that restarting MySQL worked.



                          The cause of my issue might have been the following as suggested in the answer in the aforementioned link:




                          Are you using connection pool ? If yes, then try to restart the
                          server. Probably few of the connections in your connection pool are in closed state.







                          share|improve this answer

































                            0














                            For Windows :-
                            Goto start menu write , "MySqlserver Instance Configuration Wizard" and reconfigure your mysql server instance.
                            Hope it will solve your problem.






                            share|improve this answer































                              0














                              After years having the same issue and no permanent solution this is whats solved it for the past 3 weeks (which is a record in terms of error free operation)



                              set global wait_timeout=3600;

                              set global interactive_timeout=230400;



                              Don't forget to make this permanent if it works for you.






                              share|improve this answer































                                -3














                                If you are using local emulator, you have to use IP address 10.0.2.2 instead of localhost to access to your local MySQL server.






                                share|improve this answer






























                                  25 Answers
                                  25






                                  active

                                  oldest

                                  votes








                                  25 Answers
                                  25






                                  active

                                  oldest

                                  votes









                                  active

                                  oldest

                                  votes






                                  active

                                  oldest

                                  votes









                                  339














                                  I have had the same problem in two of my programs. My error was this:



                                  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.


                                  I spent several days to solve this problem. I have tested many approaches that have been mentioned in different web sites, but non of them worked. Finally I changed my code and found out what was the problem. I'll try to tell you about different approaches and sum them up here.



                                  While I was seeking the internet to find the solution for this error, I figured out that there are many solutions that worked for at least one person, but others say that it doesn't work for them! why there are many approaches to this error?
                                  It seems this error can occur generally when there is a problem in connecting to the server. Maybe the problem is because of the wrong query string or too many connections to the database.



                                  So I suggest you to try all the solutions one by one and don't give up!



                                  Here are the solutions that I found on the internet and for each of them, there is at least on person who his problem has been solved with that solution.



                                  Tip: For the solutions that you need to change the MySQL settings, you can refer to the following files:




                                  • Linux: /etc/mysql/my.cnf or /etc/my.cnf (depending on the Linux distribution and MySQL package used)


                                  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini (Notice it's ProgramData, not Program Files)



                                  Here are the solutions:




                                  • changing "bind-address" attribute


                                  Uncomment "bind-address" attribute or change it to one of the following IPs:



                                  bind-address="127.0.0.1"



                                  or



                                  bind-address="0.0.0.0"




                                  • commenting out "skip-networking"


                                  If there is a "skip-networking" line in your MySQL config file, make it comment by adding "#" sign at the beginning of that line.




                                  • change "wait_timeout" and "interactive_timeout"


                                  Add these lines to the MySQL config file:



                                  wait_timeout = number



                                  interactive_timeout = number



                                  connect_timeout = number





                                  • Make sure Java isn't translating 'localhost' to [:::1] instead of [127.0.0.1]


                                  Since MySQL recognizes 127.0.0.1 (IPv4) but not :::1 (IPv6)



                                  This could be avoided by using one of two approaches:



                                  Option #1: In the connection string use 127.0.0.1 instead of localhost to avoid localhost being translated to :::1



                                  Option #2: Run java with the option -Djava.net.preferIPv4Stack=true to force java to use IPv4 instead of IPv6. On Linux, this could also be achieved by running (or placing it inside /etc/profile:



                                  export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"



                                  • check Operating System proxy settings, firewalls and anti-virus programs


                                  Make sure the Firewall, or Anti-virus software isn't blocking MySQL service.



                                  Stop iptables temporarily on linux. If iptables are misconfigured they may allow tcp packets to be sent to mysql port, but block tcp packets from coming back on the same connection.



                                  # Redhat enterprise and CentOS
                                  systemctl stop iptables.service
                                  # Other linux distros
                                  service iptables stop


                                  Stop anti-virus software on Windows.




                                  • change connection string


                                  Check your query string. your connection string should be some thing like this:



                                  dbName = "my_database";
                                  dbUserName = "root";
                                  dbPassword = "";
                                  String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";


                                  Make sure you don't have spaces in your string. All the connection string should be continues without any space characters.



                                  Try to replace "localhost" with the loopback address 127.0.0.1.
                                  Also try to add port number to your connection string, like:



                                  String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";


                                  Usually default port for MySQL is 3306.



                                  Don't forget to change username and password to the username and password of your MySQL server.




                                  • update your JDK driver library file

                                  • test different JDK and JREs (like JDK 6 and 7)

                                  • don't change max_allowed_packet


                                  "max_allowed_packet" is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.




                                  • change tomcat security


                                  change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no




                                  • use validationQuery property


                                  use validationQuery="select now()" to make sure each query has responses




                                  • AutoReconnect


                                  Add this code to your connection string:



                                  &autoReconnect=true&failOverReadOnly=false&maxReconnects=10




                                  Although non of these solutions worked for me, I suggest you to try them. Because there are some people who solved their problem with following these steps.



                                  But what solved my problem?



                                  My problem was that I had many SELECTs on database. Each time I was creating a connection and then closing it. Although I was closing the connection every time, but the system faced with many connections and gave me that error. What I did was that I defined my connection variable as a public (or private) variable for whole class and initialized it in the constructor. Then every time I just used that connection. It solved my problem and also increased my speed dramatically.



                                  Conclusion



                                  There is no simple and unique way to solve this problem. I suggest you to think about your own situation and choose above solutions. If you take this error at the beginning of the program and you are not able to connect to the database at all, you might have problem in your connection string. But If you take this error after several successful interaction to the database, the problem might be with number of connections and you may think about changing "wait_timeout" and other MySQL settings or rewrite your code how that reduce number of connections.






                                  share|improve this answer





















                                  • 2





                                    I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

                                    – Siddharth
                                    Apr 4 '13 at 22:06






                                  • 1





                                    @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

                                    – smonff
                                    Mar 23 '15 at 10:25






                                  • 2





                                    @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

                                    – Basil Musa
                                    Feb 7 '16 at 18:30






                                  • 1





                                    @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

                                    – thorinkor
                                    May 17 '16 at 10:34






                                  • 1





                                    After using the correct transaction manager things are really fast. Thanks.

                                    – Markus Barthlen
                                    Sep 15 '16 at 11:34
















                                  339














                                  I have had the same problem in two of my programs. My error was this:



                                  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.


                                  I spent several days to solve this problem. I have tested many approaches that have been mentioned in different web sites, but non of them worked. Finally I changed my code and found out what was the problem. I'll try to tell you about different approaches and sum them up here.



                                  While I was seeking the internet to find the solution for this error, I figured out that there are many solutions that worked for at least one person, but others say that it doesn't work for them! why there are many approaches to this error?
                                  It seems this error can occur generally when there is a problem in connecting to the server. Maybe the problem is because of the wrong query string or too many connections to the database.



                                  So I suggest you to try all the solutions one by one and don't give up!



                                  Here are the solutions that I found on the internet and for each of them, there is at least on person who his problem has been solved with that solution.



                                  Tip: For the solutions that you need to change the MySQL settings, you can refer to the following files:




                                  • Linux: /etc/mysql/my.cnf or /etc/my.cnf (depending on the Linux distribution and MySQL package used)


                                  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini (Notice it's ProgramData, not Program Files)



                                  Here are the solutions:




                                  • changing "bind-address" attribute


                                  Uncomment "bind-address" attribute or change it to one of the following IPs:



                                  bind-address="127.0.0.1"



                                  or



                                  bind-address="0.0.0.0"




                                  • commenting out "skip-networking"


                                  If there is a "skip-networking" line in your MySQL config file, make it comment by adding "#" sign at the beginning of that line.




                                  • change "wait_timeout" and "interactive_timeout"


                                  Add these lines to the MySQL config file:



                                  wait_timeout = number



                                  interactive_timeout = number



                                  connect_timeout = number





                                  • Make sure Java isn't translating 'localhost' to [:::1] instead of [127.0.0.1]


                                  Since MySQL recognizes 127.0.0.1 (IPv4) but not :::1 (IPv6)



                                  This could be avoided by using one of two approaches:



                                  Option #1: In the connection string use 127.0.0.1 instead of localhost to avoid localhost being translated to :::1



                                  Option #2: Run java with the option -Djava.net.preferIPv4Stack=true to force java to use IPv4 instead of IPv6. On Linux, this could also be achieved by running (or placing it inside /etc/profile:



                                  export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"



                                  • check Operating System proxy settings, firewalls and anti-virus programs


                                  Make sure the Firewall, or Anti-virus software isn't blocking MySQL service.



                                  Stop iptables temporarily on linux. If iptables are misconfigured they may allow tcp packets to be sent to mysql port, but block tcp packets from coming back on the same connection.



                                  # Redhat enterprise and CentOS
                                  systemctl stop iptables.service
                                  # Other linux distros
                                  service iptables stop


                                  Stop anti-virus software on Windows.




                                  • change connection string


                                  Check your query string. your connection string should be some thing like this:



                                  dbName = "my_database";
                                  dbUserName = "root";
                                  dbPassword = "";
                                  String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";


                                  Make sure you don't have spaces in your string. All the connection string should be continues without any space characters.



                                  Try to replace "localhost" with the loopback address 127.0.0.1.
                                  Also try to add port number to your connection string, like:



                                  String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";


                                  Usually default port for MySQL is 3306.



                                  Don't forget to change username and password to the username and password of your MySQL server.




                                  • update your JDK driver library file

                                  • test different JDK and JREs (like JDK 6 and 7)

                                  • don't change max_allowed_packet


                                  "max_allowed_packet" is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.




                                  • change tomcat security


                                  change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no




                                  • use validationQuery property


                                  use validationQuery="select now()" to make sure each query has responses




                                  • AutoReconnect


                                  Add this code to your connection string:



                                  &autoReconnect=true&failOverReadOnly=false&maxReconnects=10




                                  Although non of these solutions worked for me, I suggest you to try them. Because there are some people who solved their problem with following these steps.



                                  But what solved my problem?



                                  My problem was that I had many SELECTs on database. Each time I was creating a connection and then closing it. Although I was closing the connection every time, but the system faced with many connections and gave me that error. What I did was that I defined my connection variable as a public (or private) variable for whole class and initialized it in the constructor. Then every time I just used that connection. It solved my problem and also increased my speed dramatically.



                                  Conclusion



                                  There is no simple and unique way to solve this problem. I suggest you to think about your own situation and choose above solutions. If you take this error at the beginning of the program and you are not able to connect to the database at all, you might have problem in your connection string. But If you take this error after several successful interaction to the database, the problem might be with number of connections and you may think about changing "wait_timeout" and other MySQL settings or rewrite your code how that reduce number of connections.






                                  share|improve this answer





















                                  • 2





                                    I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

                                    – Siddharth
                                    Apr 4 '13 at 22:06






                                  • 1





                                    @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

                                    – smonff
                                    Mar 23 '15 at 10:25






                                  • 2





                                    @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

                                    – Basil Musa
                                    Feb 7 '16 at 18:30






                                  • 1





                                    @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

                                    – thorinkor
                                    May 17 '16 at 10:34






                                  • 1





                                    After using the correct transaction manager things are really fast. Thanks.

                                    – Markus Barthlen
                                    Sep 15 '16 at 11:34














                                  339












                                  339








                                  339







                                  I have had the same problem in two of my programs. My error was this:



                                  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.


                                  I spent several days to solve this problem. I have tested many approaches that have been mentioned in different web sites, but non of them worked. Finally I changed my code and found out what was the problem. I'll try to tell you about different approaches and sum them up here.



                                  While I was seeking the internet to find the solution for this error, I figured out that there are many solutions that worked for at least one person, but others say that it doesn't work for them! why there are many approaches to this error?
                                  It seems this error can occur generally when there is a problem in connecting to the server. Maybe the problem is because of the wrong query string or too many connections to the database.



                                  So I suggest you to try all the solutions one by one and don't give up!



                                  Here are the solutions that I found on the internet and for each of them, there is at least on person who his problem has been solved with that solution.



                                  Tip: For the solutions that you need to change the MySQL settings, you can refer to the following files:




                                  • Linux: /etc/mysql/my.cnf or /etc/my.cnf (depending on the Linux distribution and MySQL package used)


                                  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini (Notice it's ProgramData, not Program Files)



                                  Here are the solutions:




                                  • changing "bind-address" attribute


                                  Uncomment "bind-address" attribute or change it to one of the following IPs:



                                  bind-address="127.0.0.1"



                                  or



                                  bind-address="0.0.0.0"




                                  • commenting out "skip-networking"


                                  If there is a "skip-networking" line in your MySQL config file, make it comment by adding "#" sign at the beginning of that line.




                                  • change "wait_timeout" and "interactive_timeout"


                                  Add these lines to the MySQL config file:



                                  wait_timeout = number



                                  interactive_timeout = number



                                  connect_timeout = number





                                  • Make sure Java isn't translating 'localhost' to [:::1] instead of [127.0.0.1]


                                  Since MySQL recognizes 127.0.0.1 (IPv4) but not :::1 (IPv6)



                                  This could be avoided by using one of two approaches:



                                  Option #1: In the connection string use 127.0.0.1 instead of localhost to avoid localhost being translated to :::1



                                  Option #2: Run java with the option -Djava.net.preferIPv4Stack=true to force java to use IPv4 instead of IPv6. On Linux, this could also be achieved by running (or placing it inside /etc/profile:



                                  export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"



                                  • check Operating System proxy settings, firewalls and anti-virus programs


                                  Make sure the Firewall, or Anti-virus software isn't blocking MySQL service.



                                  Stop iptables temporarily on linux. If iptables are misconfigured they may allow tcp packets to be sent to mysql port, but block tcp packets from coming back on the same connection.



                                  # Redhat enterprise and CentOS
                                  systemctl stop iptables.service
                                  # Other linux distros
                                  service iptables stop


                                  Stop anti-virus software on Windows.




                                  • change connection string


                                  Check your query string. your connection string should be some thing like this:



                                  dbName = "my_database";
                                  dbUserName = "root";
                                  dbPassword = "";
                                  String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";


                                  Make sure you don't have spaces in your string. All the connection string should be continues without any space characters.



                                  Try to replace "localhost" with the loopback address 127.0.0.1.
                                  Also try to add port number to your connection string, like:



                                  String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";


                                  Usually default port for MySQL is 3306.



                                  Don't forget to change username and password to the username and password of your MySQL server.




                                  • update your JDK driver library file

                                  • test different JDK and JREs (like JDK 6 and 7)

                                  • don't change max_allowed_packet


                                  "max_allowed_packet" is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.




                                  • change tomcat security


                                  change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no




                                  • use validationQuery property


                                  use validationQuery="select now()" to make sure each query has responses




                                  • AutoReconnect


                                  Add this code to your connection string:



                                  &autoReconnect=true&failOverReadOnly=false&maxReconnects=10




                                  Although non of these solutions worked for me, I suggest you to try them. Because there are some people who solved their problem with following these steps.



                                  But what solved my problem?



                                  My problem was that I had many SELECTs on database. Each time I was creating a connection and then closing it. Although I was closing the connection every time, but the system faced with many connections and gave me that error. What I did was that I defined my connection variable as a public (or private) variable for whole class and initialized it in the constructor. Then every time I just used that connection. It solved my problem and also increased my speed dramatically.



                                  Conclusion



                                  There is no simple and unique way to solve this problem. I suggest you to think about your own situation and choose above solutions. If you take this error at the beginning of the program and you are not able to connect to the database at all, you might have problem in your connection string. But If you take this error after several successful interaction to the database, the problem might be with number of connections and you may think about changing "wait_timeout" and other MySQL settings or rewrite your code how that reduce number of connections.






                                  share|improve this answer















                                  I have had the same problem in two of my programs. My error was this:



                                  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.


                                  I spent several days to solve this problem. I have tested many approaches that have been mentioned in different web sites, but non of them worked. Finally I changed my code and found out what was the problem. I'll try to tell you about different approaches and sum them up here.



                                  While I was seeking the internet to find the solution for this error, I figured out that there are many solutions that worked for at least one person, but others say that it doesn't work for them! why there are many approaches to this error?
                                  It seems this error can occur generally when there is a problem in connecting to the server. Maybe the problem is because of the wrong query string or too many connections to the database.



                                  So I suggest you to try all the solutions one by one and don't give up!



                                  Here are the solutions that I found on the internet and for each of them, there is at least on person who his problem has been solved with that solution.



                                  Tip: For the solutions that you need to change the MySQL settings, you can refer to the following files:




                                  • Linux: /etc/mysql/my.cnf or /etc/my.cnf (depending on the Linux distribution and MySQL package used)


                                  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini (Notice it's ProgramData, not Program Files)



                                  Here are the solutions:




                                  • changing "bind-address" attribute


                                  Uncomment "bind-address" attribute or change it to one of the following IPs:



                                  bind-address="127.0.0.1"



                                  or



                                  bind-address="0.0.0.0"




                                  • commenting out "skip-networking"


                                  If there is a "skip-networking" line in your MySQL config file, make it comment by adding "#" sign at the beginning of that line.




                                  • change "wait_timeout" and "interactive_timeout"


                                  Add these lines to the MySQL config file:



                                  wait_timeout = number



                                  interactive_timeout = number



                                  connect_timeout = number





                                  • Make sure Java isn't translating 'localhost' to [:::1] instead of [127.0.0.1]


                                  Since MySQL recognizes 127.0.0.1 (IPv4) but not :::1 (IPv6)



                                  This could be avoided by using one of two approaches:



                                  Option #1: In the connection string use 127.0.0.1 instead of localhost to avoid localhost being translated to :::1



                                  Option #2: Run java with the option -Djava.net.preferIPv4Stack=true to force java to use IPv4 instead of IPv6. On Linux, this could also be achieved by running (or placing it inside /etc/profile:



                                  export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"



                                  • check Operating System proxy settings, firewalls and anti-virus programs


                                  Make sure the Firewall, or Anti-virus software isn't blocking MySQL service.



                                  Stop iptables temporarily on linux. If iptables are misconfigured they may allow tcp packets to be sent to mysql port, but block tcp packets from coming back on the same connection.



                                  # Redhat enterprise and CentOS
                                  systemctl stop iptables.service
                                  # Other linux distros
                                  service iptables stop


                                  Stop anti-virus software on Windows.




                                  • change connection string


                                  Check your query string. your connection string should be some thing like this:



                                  dbName = "my_database";
                                  dbUserName = "root";
                                  dbPassword = "";
                                  String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";


                                  Make sure you don't have spaces in your string. All the connection string should be continues without any space characters.



                                  Try to replace "localhost" with the loopback address 127.0.0.1.
                                  Also try to add port number to your connection string, like:



                                  String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";


                                  Usually default port for MySQL is 3306.



                                  Don't forget to change username and password to the username and password of your MySQL server.




                                  • update your JDK driver library file

                                  • test different JDK and JREs (like JDK 6 and 7)

                                  • don't change max_allowed_packet


                                  "max_allowed_packet" is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.




                                  • change tomcat security


                                  change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no




                                  • use validationQuery property


                                  use validationQuery="select now()" to make sure each query has responses




                                  • AutoReconnect


                                  Add this code to your connection string:



                                  &autoReconnect=true&failOverReadOnly=false&maxReconnects=10




                                  Although non of these solutions worked for me, I suggest you to try them. Because there are some people who solved their problem with following these steps.



                                  But what solved my problem?



                                  My problem was that I had many SELECTs on database. Each time I was creating a connection and then closing it. Although I was closing the connection every time, but the system faced with many connections and gave me that error. What I did was that I defined my connection variable as a public (or private) variable for whole class and initialized it in the constructor. Then every time I just used that connection. It solved my problem and also increased my speed dramatically.



                                  Conclusion



                                  There is no simple and unique way to solve this problem. I suggest you to think about your own situation and choose above solutions. If you take this error at the beginning of the program and you are not able to connect to the database at all, you might have problem in your connection string. But If you take this error after several successful interaction to the database, the problem might be with number of connections and you may think about changing "wait_timeout" and other MySQL settings or rewrite your code how that reduce number of connections.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Apr 5 '17 at 16:20

























                                  answered May 27 '12 at 7:40









                                  SoheilSoheil

                                  3,58111119




                                  3,58111119








                                  • 2





                                    I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

                                    – Siddharth
                                    Apr 4 '13 at 22:06






                                  • 1





                                    @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

                                    – smonff
                                    Mar 23 '15 at 10:25






                                  • 2





                                    @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

                                    – Basil Musa
                                    Feb 7 '16 at 18:30






                                  • 1





                                    @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

                                    – thorinkor
                                    May 17 '16 at 10:34






                                  • 1





                                    After using the correct transaction manager things are really fast. Thanks.

                                    – Markus Barthlen
                                    Sep 15 '16 at 11:34














                                  • 2





                                    I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

                                    – Siddharth
                                    Apr 4 '13 at 22:06






                                  • 1





                                    @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

                                    – smonff
                                    Mar 23 '15 at 10:25






                                  • 2





                                    @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

                                    – Basil Musa
                                    Feb 7 '16 at 18:30






                                  • 1





                                    @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

                                    – thorinkor
                                    May 17 '16 at 10:34






                                  • 1





                                    After using the correct transaction manager things are really fast. Thanks.

                                    – Markus Barthlen
                                    Sep 15 '16 at 11:34








                                  2




                                  2





                                  I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

                                  – Siddharth
                                  Apr 4 '13 at 22:06





                                  I added wait_timeout only, referred to dev.mysql.com/doc/refman/5.1/en/…

                                  – Siddharth
                                  Apr 4 '13 at 22:06




                                  1




                                  1





                                  @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

                                  – smonff
                                  Mar 23 '15 at 10:25





                                  @soheil There is no simple and unique way to solve this problem. Sure, but anyway, you made my day. I love you.

                                  – smonff
                                  Mar 23 '15 at 10:25




                                  2




                                  2





                                  @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

                                  – Basil Musa
                                  Feb 7 '16 at 18:30





                                  @Soheil Can you add "Disabling iptables temporarily", this was my problem. iptables was misconfigured and was allowing tcp packets to be sent to mysql port, but blocked tcp packets from coming back on the same connection.

                                  – Basil Musa
                                  Feb 7 '16 at 18:30




                                  1




                                  1





                                  @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

                                  – thorinkor
                                  May 17 '16 at 10:34





                                  @Soheil thanks for the solution - for me changing the wait_timeout parameter in MySQL config did the trick! The initial value was set only to "300"!

                                  – thorinkor
                                  May 17 '16 at 10:34




                                  1




                                  1





                                  After using the correct transaction manager things are really fast. Thanks.

                                  – Markus Barthlen
                                  Sep 15 '16 at 11:34





                                  After using the correct transaction manager things are really fast. Thanks.

                                  – Markus Barthlen
                                  Sep 15 '16 at 11:34













                                  12














                                  If you are using MAMP PRO, the easy fix, which I really wish I had realized before I started searching the internet for days trying to figure this out. Its really this simple...



                                  You just have to click "Allow Network Access to MySQL" from the MAMP MySQL tab.



                                  Really, thats it.



                                  Oh, and you MIGHT have to still change your bind address to either 0.0.0.0 or 127.0.0.1 like outlined in the posts above, but clicking that box alone will probably solve your problems if you are a MAMP user.






                                  share|improve this answer
























                                  • Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

                                    – Shantanu
                                    Jul 30 '15 at 8:45











                                  • For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

                                    – Strainy
                                    Jan 10 '16 at 20:23











                                  • My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

                                    – kimbaudi
                                    Jan 10 '17 at 20:21
















                                  12














                                  If you are using MAMP PRO, the easy fix, which I really wish I had realized before I started searching the internet for days trying to figure this out. Its really this simple...



                                  You just have to click "Allow Network Access to MySQL" from the MAMP MySQL tab.



                                  Really, thats it.



                                  Oh, and you MIGHT have to still change your bind address to either 0.0.0.0 or 127.0.0.1 like outlined in the posts above, but clicking that box alone will probably solve your problems if you are a MAMP user.






                                  share|improve this answer
























                                  • Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

                                    – Shantanu
                                    Jul 30 '15 at 8:45











                                  • For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

                                    – Strainy
                                    Jan 10 '16 at 20:23











                                  • My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

                                    – kimbaudi
                                    Jan 10 '17 at 20:21














                                  12












                                  12








                                  12







                                  If you are using MAMP PRO, the easy fix, which I really wish I had realized before I started searching the internet for days trying to figure this out. Its really this simple...



                                  You just have to click "Allow Network Access to MySQL" from the MAMP MySQL tab.



                                  Really, thats it.



                                  Oh, and you MIGHT have to still change your bind address to either 0.0.0.0 or 127.0.0.1 like outlined in the posts above, but clicking that box alone will probably solve your problems if you are a MAMP user.






                                  share|improve this answer













                                  If you are using MAMP PRO, the easy fix, which I really wish I had realized before I started searching the internet for days trying to figure this out. Its really this simple...



                                  You just have to click "Allow Network Access to MySQL" from the MAMP MySQL tab.



                                  Really, thats it.



                                  Oh, and you MIGHT have to still change your bind address to either 0.0.0.0 or 127.0.0.1 like outlined in the posts above, but clicking that box alone will probably solve your problems if you are a MAMP user.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Dec 30 '14 at 6:08









                                  Peter John JosephPeter John Joseph

                                  175212




                                  175212













                                  • Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

                                    – Shantanu
                                    Jul 30 '15 at 8:45











                                  • For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

                                    – Strainy
                                    Jan 10 '16 at 20:23











                                  • My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

                                    – kimbaudi
                                    Jan 10 '17 at 20:21



















                                  • Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

                                    – Shantanu
                                    Jul 30 '15 at 8:45











                                  • For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

                                    – Strainy
                                    Jan 10 '16 at 20:23











                                  • My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

                                    – kimbaudi
                                    Jan 10 '17 at 20:21

















                                  Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

                                  – Shantanu
                                  Jul 30 '15 at 8:45





                                  Saved me a lot of time this did. I could feel myself reaching boiling point when I knew that this would just be a one liner solution.

                                  – Shantanu
                                  Jul 30 '15 at 8:45













                                  For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

                                  – Strainy
                                  Jan 10 '16 at 20:23





                                  For me the ports were completely different to what MAMP said they were on the start page. Go into the MAMP preferences and check the ports tab to see what your actual MySQL port is.

                                  – Strainy
                                  Jan 10 '16 at 20:23













                                  My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

                                  – kimbaudi
                                  Jan 10 '17 at 20:21





                                  My app worked on Windows and Ubuntu, but not on my Mac which has MAMP PRO. This is also how I got my app working on Mac.

                                  – kimbaudi
                                  Jan 10 '17 at 20:21











                                  5














                                  Setting the bind-address to the server's network IP instead of the localhost default, and setting privileges on my user worked for me.



                                  my.cnf:



                                  bind-address = 192.168.123.456


                                  MySql Console:



                                  GRANT ALL PRIVILEGES ON dbname.* to username@'%' IDENTIFIED BY 'password';





                                  share|improve this answer



















                                  • 1





                                    Or use 0.0.0.0 for all interfaces...

                                    – Eric Kramer
                                    Jan 21 '16 at 19:14











                                  • answer worked for me, can you describe what does @'%' means in above mysql directive?

                                    – alex
                                    Sep 26 '16 at 5:27













                                  • bind-address = 0.0.0.0 worked for me.

                                    – Daddy32
                                    Aug 2 '17 at 11:54
















                                  5














                                  Setting the bind-address to the server's network IP instead of the localhost default, and setting privileges on my user worked for me.



                                  my.cnf:



                                  bind-address = 192.168.123.456


                                  MySql Console:



                                  GRANT ALL PRIVILEGES ON dbname.* to username@'%' IDENTIFIED BY 'password';





                                  share|improve this answer



















                                  • 1





                                    Or use 0.0.0.0 for all interfaces...

                                    – Eric Kramer
                                    Jan 21 '16 at 19:14











                                  • answer worked for me, can you describe what does @'%' means in above mysql directive?

                                    – alex
                                    Sep 26 '16 at 5:27













                                  • bind-address = 0.0.0.0 worked for me.

                                    – Daddy32
                                    Aug 2 '17 at 11:54














                                  5












                                  5








                                  5







                                  Setting the bind-address to the server's network IP instead of the localhost default, and setting privileges on my user worked for me.



                                  my.cnf:



                                  bind-address = 192.168.123.456


                                  MySql Console:



                                  GRANT ALL PRIVILEGES ON dbname.* to username@'%' IDENTIFIED BY 'password';





                                  share|improve this answer













                                  Setting the bind-address to the server's network IP instead of the localhost default, and setting privileges on my user worked for me.



                                  my.cnf:



                                  bind-address = 192.168.123.456


                                  MySql Console:



                                  GRANT ALL PRIVILEGES ON dbname.* to username@'%' IDENTIFIED BY 'password';






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Apr 3 '13 at 21:14









                                  Kevin LawrenceKevin Lawrence

                                  656917




                                  656917








                                  • 1





                                    Or use 0.0.0.0 for all interfaces...

                                    – Eric Kramer
                                    Jan 21 '16 at 19:14











                                  • answer worked for me, can you describe what does @'%' means in above mysql directive?

                                    – alex
                                    Sep 26 '16 at 5:27













                                  • bind-address = 0.0.0.0 worked for me.

                                    – Daddy32
                                    Aug 2 '17 at 11:54














                                  • 1





                                    Or use 0.0.0.0 for all interfaces...

                                    – Eric Kramer
                                    Jan 21 '16 at 19:14











                                  • answer worked for me, can you describe what does @'%' means in above mysql directive?

                                    – alex
                                    Sep 26 '16 at 5:27













                                  • bind-address = 0.0.0.0 worked for me.

                                    – Daddy32
                                    Aug 2 '17 at 11:54








                                  1




                                  1





                                  Or use 0.0.0.0 for all interfaces...

                                  – Eric Kramer
                                  Jan 21 '16 at 19:14





                                  Or use 0.0.0.0 for all interfaces...

                                  – Eric Kramer
                                  Jan 21 '16 at 19:14













                                  answer worked for me, can you describe what does @'%' means in above mysql directive?

                                  – alex
                                  Sep 26 '16 at 5:27







                                  answer worked for me, can you describe what does @'%' means in above mysql directive?

                                  – alex
                                  Sep 26 '16 at 5:27















                                  bind-address = 0.0.0.0 worked for me.

                                  – Daddy32
                                  Aug 2 '17 at 11:54





                                  bind-address = 0.0.0.0 worked for me.

                                  – Daddy32
                                  Aug 2 '17 at 11:54











                                  4














                                  In my case,




                                  1. Change the remote machine mysql configuration at /etc/mysql/my.cnf: change
                                    bind-address = 127.0.0.1
                                    to
                                    #bind-address = 127.0.0.1


                                  2. On the remote machine, change mysql user permissions with
                                    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';


                                  3. IMPORTANT: restart mysql on the remote machine: sudo /etc/init.d/mysql restart







                                  share|improve this answer
























                                  • After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

                                    – Luis Crespo
                                    May 7 '18 at 14:26
















                                  4














                                  In my case,




                                  1. Change the remote machine mysql configuration at /etc/mysql/my.cnf: change
                                    bind-address = 127.0.0.1
                                    to
                                    #bind-address = 127.0.0.1


                                  2. On the remote machine, change mysql user permissions with
                                    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';


                                  3. IMPORTANT: restart mysql on the remote machine: sudo /etc/init.d/mysql restart







                                  share|improve this answer
























                                  • After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

                                    – Luis Crespo
                                    May 7 '18 at 14:26














                                  4












                                  4








                                  4







                                  In my case,




                                  1. Change the remote machine mysql configuration at /etc/mysql/my.cnf: change
                                    bind-address = 127.0.0.1
                                    to
                                    #bind-address = 127.0.0.1


                                  2. On the remote machine, change mysql user permissions with
                                    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';


                                  3. IMPORTANT: restart mysql on the remote machine: sudo /etc/init.d/mysql restart







                                  share|improve this answer













                                  In my case,




                                  1. Change the remote machine mysql configuration at /etc/mysql/my.cnf: change
                                    bind-address = 127.0.0.1
                                    to
                                    #bind-address = 127.0.0.1


                                  2. On the remote machine, change mysql user permissions with
                                    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';


                                  3. IMPORTANT: restart mysql on the remote machine: sudo /etc/init.d/mysql restart








                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered May 13 '14 at 19:39









                                  cindyxiaoxiaolicindyxiaoxiaoli

                                  540315




                                  540315













                                  • After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

                                    – Luis Crespo
                                    May 7 '18 at 14:26



















                                  • After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

                                    – Luis Crespo
                                    May 7 '18 at 14:26

















                                  After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

                                  – Luis Crespo
                                  May 7 '18 at 14:26





                                  After installing MySQL in Ubuntu/Debian, the setup process is secure and prevents any external access by default. These steps are always required in order to access MySQL from any remote machine.

                                  – Luis Crespo
                                  May 7 '18 at 14:26











                                  3














                                  As the detailed answer above says, this error can be caused by many things.



                                  I had this problem too. My setup was Mac OSX 10.8, using a Vagrant managed VirtualBox VM of Ubuntu 12.04, with MySQL 5.5.34.



                                  I had correctly setup port forwarding in the Vagrant config file. I could telnet to the MySQL instance both from my Mac and from within the VM. So I knew the MySQL daemon was running and reachable. But when I tried to connect over JDBC, I got the "Communications link failure" error.



                                  In my case, the problem was solved by editing the /etc/mysql/my.cnf file. Specifically, I commented out the "#bind-address=127.0.0.1" line.






                                  share|improve this answer
























                                  • Where did you change this? Host or Vagrant MySql?

                                    – Joe
                                    Mar 28 '18 at 4:48











                                  • I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

                                    – devdanke
                                    Apr 11 '18 at 4:14
















                                  3














                                  As the detailed answer above says, this error can be caused by many things.



                                  I had this problem too. My setup was Mac OSX 10.8, using a Vagrant managed VirtualBox VM of Ubuntu 12.04, with MySQL 5.5.34.



                                  I had correctly setup port forwarding in the Vagrant config file. I could telnet to the MySQL instance both from my Mac and from within the VM. So I knew the MySQL daemon was running and reachable. But when I tried to connect over JDBC, I got the "Communications link failure" error.



                                  In my case, the problem was solved by editing the /etc/mysql/my.cnf file. Specifically, I commented out the "#bind-address=127.0.0.1" line.






                                  share|improve this answer
























                                  • Where did you change this? Host or Vagrant MySql?

                                    – Joe
                                    Mar 28 '18 at 4:48











                                  • I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

                                    – devdanke
                                    Apr 11 '18 at 4:14














                                  3












                                  3








                                  3







                                  As the detailed answer above says, this error can be caused by many things.



                                  I had this problem too. My setup was Mac OSX 10.8, using a Vagrant managed VirtualBox VM of Ubuntu 12.04, with MySQL 5.5.34.



                                  I had correctly setup port forwarding in the Vagrant config file. I could telnet to the MySQL instance both from my Mac and from within the VM. So I knew the MySQL daemon was running and reachable. But when I tried to connect over JDBC, I got the "Communications link failure" error.



                                  In my case, the problem was solved by editing the /etc/mysql/my.cnf file. Specifically, I commented out the "#bind-address=127.0.0.1" line.






                                  share|improve this answer













                                  As the detailed answer above says, this error can be caused by many things.



                                  I had this problem too. My setup was Mac OSX 10.8, using a Vagrant managed VirtualBox VM of Ubuntu 12.04, with MySQL 5.5.34.



                                  I had correctly setup port forwarding in the Vagrant config file. I could telnet to the MySQL instance both from my Mac and from within the VM. So I knew the MySQL daemon was running and reachable. But when I tried to connect over JDBC, I got the "Communications link failure" error.



                                  In my case, the problem was solved by editing the /etc/mysql/my.cnf file. Specifically, I commented out the "#bind-address=127.0.0.1" line.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Feb 12 '14 at 2:57









                                  devdankedevdanke

                                  864918




                                  864918













                                  • Where did you change this? Host or Vagrant MySql?

                                    – Joe
                                    Mar 28 '18 at 4:48











                                  • I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

                                    – devdanke
                                    Apr 11 '18 at 4:14



















                                  • Where did you change this? Host or Vagrant MySql?

                                    – Joe
                                    Mar 28 '18 at 4:48











                                  • I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

                                    – devdanke
                                    Apr 11 '18 at 4:14

















                                  Where did you change this? Host or Vagrant MySql?

                                  – Joe
                                  Mar 28 '18 at 4:48





                                  Where did you change this? Host or Vagrant MySql?

                                  – Joe
                                  Mar 28 '18 at 4:48













                                  I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

                                  – devdanke
                                  Apr 11 '18 at 4:14





                                  I made the config change in the guest VM, where MySQL was running. I didn't want MySQL running directly on my Mac, so I used a VM.

                                  – devdanke
                                  Apr 11 '18 at 4:14











                                  3














                                  I've just faced the same problem.
                                  It happened because the MySQL Daemon was binded to the IP of the machine, which is required to make connection with an user that has permission to connect @your_machine.
                                  In this case, the user should have permission to connect USER_NAME@MACHINE_NAME_OR_IP



                                  I wanted remote access to my machine so I changed in my.cnf from



                                  bind-address = MY_IP_ADDRESS


                                  To



                                  bind-address = 0.0.0.0


                                  Which will allow an user from localhost AND even outside (in my case) to connect to the instance.
                                  Both below permissions will work if you bind the MySQL to 0.0.0.0:



                                  USER_NAME@MACHINE_NAME_OR_IP

                                  USER_NAME@localhost





                                  share|improve this answer






























                                    3














                                    I've just faced the same problem.
                                    It happened because the MySQL Daemon was binded to the IP of the machine, which is required to make connection with an user that has permission to connect @your_machine.
                                    In this case, the user should have permission to connect USER_NAME@MACHINE_NAME_OR_IP



                                    I wanted remote access to my machine so I changed in my.cnf from



                                    bind-address = MY_IP_ADDRESS


                                    To



                                    bind-address = 0.0.0.0


                                    Which will allow an user from localhost AND even outside (in my case) to connect to the instance.
                                    Both below permissions will work if you bind the MySQL to 0.0.0.0:



                                    USER_NAME@MACHINE_NAME_OR_IP

                                    USER_NAME@localhost





                                    share|improve this answer




























                                      3












                                      3








                                      3







                                      I've just faced the same problem.
                                      It happened because the MySQL Daemon was binded to the IP of the machine, which is required to make connection with an user that has permission to connect @your_machine.
                                      In this case, the user should have permission to connect USER_NAME@MACHINE_NAME_OR_IP



                                      I wanted remote access to my machine so I changed in my.cnf from



                                      bind-address = MY_IP_ADDRESS


                                      To



                                      bind-address = 0.0.0.0


                                      Which will allow an user from localhost AND even outside (in my case) to connect to the instance.
                                      Both below permissions will work if you bind the MySQL to 0.0.0.0:



                                      USER_NAME@MACHINE_NAME_OR_IP

                                      USER_NAME@localhost





                                      share|improve this answer















                                      I've just faced the same problem.
                                      It happened because the MySQL Daemon was binded to the IP of the machine, which is required to make connection with an user that has permission to connect @your_machine.
                                      In this case, the user should have permission to connect USER_NAME@MACHINE_NAME_OR_IP



                                      I wanted remote access to my machine so I changed in my.cnf from



                                      bind-address = MY_IP_ADDRESS


                                      To



                                      bind-address = 0.0.0.0


                                      Which will allow an user from localhost AND even outside (in my case) to connect to the instance.
                                      Both below permissions will work if you bind the MySQL to 0.0.0.0:



                                      USER_NAME@MACHINE_NAME_OR_IP

                                      USER_NAME@localhost






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Dec 11 '14 at 23:08

























                                      answered Mar 19 '14 at 4:28









                                      RenannRenann

                                      1931111




                                      1931111























                                          2














                                          In my case it was an idle timeout, that caused the connection to be dropped on the server. The connection was kept open, but not used for a long period of time. Then a client restart works, while I believe a reconnect will work as well.



                                          A not bad solution is to have a daemon/service to ping the connection from time to time.






                                          share|improve this answer






























                                            2














                                            In my case it was an idle timeout, that caused the connection to be dropped on the server. The connection was kept open, but not used for a long period of time. Then a client restart works, while I believe a reconnect will work as well.



                                            A not bad solution is to have a daemon/service to ping the connection from time to time.






                                            share|improve this answer




























                                              2












                                              2








                                              2







                                              In my case it was an idle timeout, that caused the connection to be dropped on the server. The connection was kept open, but not used for a long period of time. Then a client restart works, while I believe a reconnect will work as well.



                                              A not bad solution is to have a daemon/service to ping the connection from time to time.






                                              share|improve this answer















                                              In my case it was an idle timeout, that caused the connection to be dropped on the server. The connection was kept open, but not used for a long period of time. Then a client restart works, while I believe a reconnect will work as well.



                                              A not bad solution is to have a daemon/service to ping the connection from time to time.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Sep 30 '12 at 14:46

























                                              answered Sep 20 '12 at 15:41









                                              fuocofuoco

                                              212




                                              212























                                                  2














                                                  In my case (I am a noob), I was testing Servlet that make database connection with MySQL and one of the Exception is the one mentioned above.



                                                  It made my head swing for some seconds but I came to realize that it was because I have not started my MySQL server in localhost.

                                                  After starting the server, the problem was fixed.



                                                  So, check whether MySQL server is running properly.






                                                  share|improve this answer




























                                                    2














                                                    In my case (I am a noob), I was testing Servlet that make database connection with MySQL and one of the Exception is the one mentioned above.



                                                    It made my head swing for some seconds but I came to realize that it was because I have not started my MySQL server in localhost.

                                                    After starting the server, the problem was fixed.



                                                    So, check whether MySQL server is running properly.






                                                    share|improve this answer


























                                                      2












                                                      2








                                                      2







                                                      In my case (I am a noob), I was testing Servlet that make database connection with MySQL and one of the Exception is the one mentioned above.



                                                      It made my head swing for some seconds but I came to realize that it was because I have not started my MySQL server in localhost.

                                                      After starting the server, the problem was fixed.



                                                      So, check whether MySQL server is running properly.






                                                      share|improve this answer













                                                      In my case (I am a noob), I was testing Servlet that make database connection with MySQL and one of the Exception is the one mentioned above.



                                                      It made my head swing for some seconds but I came to realize that it was because I have not started my MySQL server in localhost.

                                                      After starting the server, the problem was fixed.



                                                      So, check whether MySQL server is running properly.







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Sep 19 '15 at 9:54









                                                      BarunBarun

                                                      2,16511724




                                                      2,16511724























                                                          1














                                                          For me the solution was to change in the conf file of mysql server the parameter bind-address="127.0.0.1" or bind-address="x.x.x.x" to bind-address="0.0.0.0".
                                                          Thanks.






                                                          share|improve this answer




























                                                            1














                                                            For me the solution was to change in the conf file of mysql server the parameter bind-address="127.0.0.1" or bind-address="x.x.x.x" to bind-address="0.0.0.0".
                                                            Thanks.






                                                            share|improve this answer


























                                                              1












                                                              1








                                                              1







                                                              For me the solution was to change in the conf file of mysql server the parameter bind-address="127.0.0.1" or bind-address="x.x.x.x" to bind-address="0.0.0.0".
                                                              Thanks.






                                                              share|improve this answer













                                                              For me the solution was to change in the conf file of mysql server the parameter bind-address="127.0.0.1" or bind-address="x.x.x.x" to bind-address="0.0.0.0".
                                                              Thanks.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Jul 30 '14 at 9:53









                                                              jpenaabjpenaab

                                                              191




                                                              191























                                                                  1














                                                                  In case you are having problem with a set of Docker containers, then make sure that you do not only EXPOSE the port 3306, but as well map the port from outside the container -p 3306:3306. For docker-compose.yml:



                                                                  version: '2'

                                                                  services:
                                                                  mdb:
                                                                  image: mariadb:10.1
                                                                  ports:
                                                                  - "3306:3306"






                                                                  share|improve this answer



















                                                                  • 2





                                                                    relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

                                                                    – chris.currin
                                                                    Nov 15 '17 at 9:09






                                                                  • 2





                                                                    Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

                                                                    – prayagupd
                                                                    Jun 26 '18 at 6:19


















                                                                  1














                                                                  In case you are having problem with a set of Docker containers, then make sure that you do not only EXPOSE the port 3306, but as well map the port from outside the container -p 3306:3306. For docker-compose.yml:



                                                                  version: '2'

                                                                  services:
                                                                  mdb:
                                                                  image: mariadb:10.1
                                                                  ports:
                                                                  - "3306:3306"






                                                                  share|improve this answer



















                                                                  • 2





                                                                    relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

                                                                    – chris.currin
                                                                    Nov 15 '17 at 9:09






                                                                  • 2





                                                                    Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

                                                                    – prayagupd
                                                                    Jun 26 '18 at 6:19
















                                                                  1












                                                                  1








                                                                  1







                                                                  In case you are having problem with a set of Docker containers, then make sure that you do not only EXPOSE the port 3306, but as well map the port from outside the container -p 3306:3306. For docker-compose.yml:



                                                                  version: '2'

                                                                  services:
                                                                  mdb:
                                                                  image: mariadb:10.1
                                                                  ports:
                                                                  - "3306:3306"






                                                                  share|improve this answer













                                                                  In case you are having problem with a set of Docker containers, then make sure that you do not only EXPOSE the port 3306, but as well map the port from outside the container -p 3306:3306. For docker-compose.yml:



                                                                  version: '2'

                                                                  services:
                                                                  mdb:
                                                                  image: mariadb:10.1
                                                                  ports:
                                                                  - "3306:3306"







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Mar 23 '16 at 11:46









                                                                  kaiserkaiser

                                                                  15k157394




                                                                  15k157394








                                                                  • 2





                                                                    relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

                                                                    – chris.currin
                                                                    Nov 15 '17 at 9:09






                                                                  • 2





                                                                    Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

                                                                    – prayagupd
                                                                    Jun 26 '18 at 6:19
















                                                                  • 2





                                                                    relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

                                                                    – chris.currin
                                                                    Nov 15 '17 at 9:09






                                                                  • 2





                                                                    Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

                                                                    – prayagupd
                                                                    Jun 26 '18 at 6:19










                                                                  2




                                                                  2





                                                                  relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

                                                                  – chris.currin
                                                                  Nov 15 '17 at 9:09





                                                                  relatedly, I was trying to connect using localhost or 127.0.0.1 or 0.0.0.0 or fixed ip, but needed to connect using the service name (here: jdbc:mysql://mdb:3306/... )

                                                                  – chris.currin
                                                                  Nov 15 '17 at 9:09




                                                                  2




                                                                  2





                                                                  Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

                                                                  – prayagupd
                                                                  Jun 26 '18 at 6:19







                                                                  Like @chris.currin mentioned it's important to provide container_name while accessing from another docker_container. Example "jdbc:mysql://mysql_container:3306/db_name?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"

                                                                  – prayagupd
                                                                  Jun 26 '18 at 6:19













                                                                  0














                                                                  It happens (in my case) when there is not enough memory for MySQL. A restart fixes it, but if that's the case consider a nachine with more memory, or limit the memory taken by jvms






                                                                  share|improve this answer
























                                                                  • Limiting the memory or just getting more memory seems like a temporary solution does it not?

                                                                    – Kerem
                                                                    Mar 18 '15 at 2:39
















                                                                  0














                                                                  It happens (in my case) when there is not enough memory for MySQL. A restart fixes it, but if that's the case consider a nachine with more memory, or limit the memory taken by jvms






                                                                  share|improve this answer
























                                                                  • Limiting the memory or just getting more memory seems like a temporary solution does it not?

                                                                    – Kerem
                                                                    Mar 18 '15 at 2:39














                                                                  0












                                                                  0








                                                                  0







                                                                  It happens (in my case) when there is not enough memory for MySQL. A restart fixes it, but if that's the case consider a nachine with more memory, or limit the memory taken by jvms






                                                                  share|improve this answer













                                                                  It happens (in my case) when there is not enough memory for MySQL. A restart fixes it, but if that's the case consider a nachine with more memory, or limit the memory taken by jvms







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered May 27 '12 at 7:47









                                                                  BozhoBozho

                                                                  491k1089621075




                                                                  491k1089621075













                                                                  • Limiting the memory or just getting more memory seems like a temporary solution does it not?

                                                                    – Kerem
                                                                    Mar 18 '15 at 2:39



















                                                                  • Limiting the memory or just getting more memory seems like a temporary solution does it not?

                                                                    – Kerem
                                                                    Mar 18 '15 at 2:39

















                                                                  Limiting the memory or just getting more memory seems like a temporary solution does it not?

                                                                  – Kerem
                                                                  Mar 18 '15 at 2:39





                                                                  Limiting the memory or just getting more memory seems like a temporary solution does it not?

                                                                  – Kerem
                                                                  Mar 18 '15 at 2:39











                                                                  0














                                                                  Go to Windows services in the control panel and start the MySQL service. For me it worked. When I was doing a Java EE project I got this error" Communication link failure". I restarted my system and then it worked.



                                                                  After that I again got the same error even after restarting my system. Then I tried to open the MySQL command line console and login with root, even then it gave me an error.



                                                                  Finally when I started the MySQL service from Windows services, it worked.






                                                                  share|improve this answer






























                                                                    0














                                                                    Go to Windows services in the control panel and start the MySQL service. For me it worked. When I was doing a Java EE project I got this error" Communication link failure". I restarted my system and then it worked.



                                                                    After that I again got the same error even after restarting my system. Then I tried to open the MySQL command line console and login with root, even then it gave me an error.



                                                                    Finally when I started the MySQL service from Windows services, it worked.






                                                                    share|improve this answer




























                                                                      0












                                                                      0








                                                                      0







                                                                      Go to Windows services in the control panel and start the MySQL service. For me it worked. When I was doing a Java EE project I got this error" Communication link failure". I restarted my system and then it worked.



                                                                      After that I again got the same error even after restarting my system. Then I tried to open the MySQL command line console and login with root, even then it gave me an error.



                                                                      Finally when I started the MySQL service from Windows services, it worked.






                                                                      share|improve this answer















                                                                      Go to Windows services in the control panel and start the MySQL service. For me it worked. When I was doing a Java EE project I got this error" Communication link failure". I restarted my system and then it worked.



                                                                      After that I again got the same error even after restarting my system. Then I tried to open the MySQL command line console and login with root, even then it gave me an error.



                                                                      Finally when I started the MySQL service from Windows services, it worked.







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Mar 10 '13 at 9:39









                                                                      Arjan Tijms

                                                                      34.5k994130




                                                                      34.5k994130










                                                                      answered Mar 6 '13 at 7:34









                                                                      tinkutinku

                                                                      319718




                                                                      319718























                                                                          0














                                                                          Had the same.
                                                                          Removing port helped in my case, so I left it as jdbc:mysql://localhost/






                                                                          share|improve this answer




























                                                                            0














                                                                            Had the same.
                                                                            Removing port helped in my case, so I left it as jdbc:mysql://localhost/






                                                                            share|improve this answer


























                                                                              0












                                                                              0








                                                                              0







                                                                              Had the same.
                                                                              Removing port helped in my case, so I left it as jdbc:mysql://localhost/






                                                                              share|improve this answer













                                                                              Had the same.
                                                                              Removing port helped in my case, so I left it as jdbc:mysql://localhost/







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Mar 17 '13 at 19:24









                                                                              user2180110user2180110

                                                                              1




                                                                              1























                                                                                  0














                                                                                  If you are using hibernate, this error can be caused for keeping open a Session object more time than wait_timeout



                                                                                  I've documented a case in here for those who are interested.






                                                                                  share|improve this answer




























                                                                                    0














                                                                                    If you are using hibernate, this error can be caused for keeping open a Session object more time than wait_timeout



                                                                                    I've documented a case in here for those who are interested.






                                                                                    share|improve this answer


























                                                                                      0












                                                                                      0








                                                                                      0







                                                                                      If you are using hibernate, this error can be caused for keeping open a Session object more time than wait_timeout



                                                                                      I've documented a case in here for those who are interested.






                                                                                      share|improve this answer













                                                                                      If you are using hibernate, this error can be caused for keeping open a Session object more time than wait_timeout



                                                                                      I've documented a case in here for those who are interested.







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered Sep 3 '13 at 16:01









                                                                                      Raul LunaRaul Luna

                                                                                      1,34711422




                                                                                      1,34711422























                                                                                          0














                                                                                          I found the solution



                                                                                          since MySQL need the Localhost in-order to work.



                                                                                          go to /etc/network/interfaces file and make sure you have the localhost configuration set there:



                                                                                          auto lo
                                                                                          iface lo inet loopback


                                                                                          NOW RESTART the Networking subsystem and the MySQL Services:



                                                                                          sudo /etc/init.d/networking restart



                                                                                          sudo /etc/init.d/mysql restart



                                                                                          Try it now






                                                                                          share|improve this answer
























                                                                                          • doesn't work on Mac

                                                                                            – Meetai.com
                                                                                            Jun 29 '14 at 9:57











                                                                                          • not sure about Mac, this worked for me on Linux Debian.

                                                                                            – Mahmoud Zalt
                                                                                            Jun 30 '14 at 14:51






                                                                                          • 1





                                                                                            Ok. This worked after changing MySQL port and connecting to that new port.

                                                                                            – Meetai.com
                                                                                            Jul 1 '14 at 0:26
















                                                                                          0














                                                                                          I found the solution



                                                                                          since MySQL need the Localhost in-order to work.



                                                                                          go to /etc/network/interfaces file and make sure you have the localhost configuration set there:



                                                                                          auto lo
                                                                                          iface lo inet loopback


                                                                                          NOW RESTART the Networking subsystem and the MySQL Services:



                                                                                          sudo /etc/init.d/networking restart



                                                                                          sudo /etc/init.d/mysql restart



                                                                                          Try it now






                                                                                          share|improve this answer
























                                                                                          • doesn't work on Mac

                                                                                            – Meetai.com
                                                                                            Jun 29 '14 at 9:57











                                                                                          • not sure about Mac, this worked for me on Linux Debian.

                                                                                            – Mahmoud Zalt
                                                                                            Jun 30 '14 at 14:51






                                                                                          • 1





                                                                                            Ok. This worked after changing MySQL port and connecting to that new port.

                                                                                            – Meetai.com
                                                                                            Jul 1 '14 at 0:26














                                                                                          0












                                                                                          0








                                                                                          0







                                                                                          I found the solution



                                                                                          since MySQL need the Localhost in-order to work.



                                                                                          go to /etc/network/interfaces file and make sure you have the localhost configuration set there:



                                                                                          auto lo
                                                                                          iface lo inet loopback


                                                                                          NOW RESTART the Networking subsystem and the MySQL Services:



                                                                                          sudo /etc/init.d/networking restart



                                                                                          sudo /etc/init.d/mysql restart



                                                                                          Try it now






                                                                                          share|improve this answer













                                                                                          I found the solution



                                                                                          since MySQL need the Localhost in-order to work.



                                                                                          go to /etc/network/interfaces file and make sure you have the localhost configuration set there:



                                                                                          auto lo
                                                                                          iface lo inet loopback


                                                                                          NOW RESTART the Networking subsystem and the MySQL Services:



                                                                                          sudo /etc/init.d/networking restart



                                                                                          sudo /etc/init.d/mysql restart



                                                                                          Try it now







                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Sep 13 '13 at 11:54









                                                                                          Mahmoud ZaltMahmoud Zalt

                                                                                          15.5k66057




                                                                                          15.5k66057













                                                                                          • doesn't work on Mac

                                                                                            – Meetai.com
                                                                                            Jun 29 '14 at 9:57











                                                                                          • not sure about Mac, this worked for me on Linux Debian.

                                                                                            – Mahmoud Zalt
                                                                                            Jun 30 '14 at 14:51






                                                                                          • 1





                                                                                            Ok. This worked after changing MySQL port and connecting to that new port.

                                                                                            – Meetai.com
                                                                                            Jul 1 '14 at 0:26



















                                                                                          • doesn't work on Mac

                                                                                            – Meetai.com
                                                                                            Jun 29 '14 at 9:57











                                                                                          • not sure about Mac, this worked for me on Linux Debian.

                                                                                            – Mahmoud Zalt
                                                                                            Jun 30 '14 at 14:51






                                                                                          • 1





                                                                                            Ok. This worked after changing MySQL port and connecting to that new port.

                                                                                            – Meetai.com
                                                                                            Jul 1 '14 at 0:26

















                                                                                          doesn't work on Mac

                                                                                          – Meetai.com
                                                                                          Jun 29 '14 at 9:57





                                                                                          doesn't work on Mac

                                                                                          – Meetai.com
                                                                                          Jun 29 '14 at 9:57













                                                                                          not sure about Mac, this worked for me on Linux Debian.

                                                                                          – Mahmoud Zalt
                                                                                          Jun 30 '14 at 14:51





                                                                                          not sure about Mac, this worked for me on Linux Debian.

                                                                                          – Mahmoud Zalt
                                                                                          Jun 30 '14 at 14:51




                                                                                          1




                                                                                          1





                                                                                          Ok. This worked after changing MySQL port and connecting to that new port.

                                                                                          – Meetai.com
                                                                                          Jul 1 '14 at 0:26





                                                                                          Ok. This worked after changing MySQL port and connecting to that new port.

                                                                                          – Meetai.com
                                                                                          Jul 1 '14 at 0:26











                                                                                          0














                                                                                          It is majorly because of weak connection between mysql client and remote mysql server.



                                                                                          In my case it is because of flaky VPN connection.






                                                                                          share|improve this answer




























                                                                                            0














                                                                                            It is majorly because of weak connection between mysql client and remote mysql server.



                                                                                            In my case it is because of flaky VPN connection.






                                                                                            share|improve this answer


























                                                                                              0












                                                                                              0








                                                                                              0







                                                                                              It is majorly because of weak connection between mysql client and remote mysql server.



                                                                                              In my case it is because of flaky VPN connection.






                                                                                              share|improve this answer













                                                                                              It is majorly because of weak connection between mysql client and remote mysql server.



                                                                                              In my case it is because of flaky VPN connection.







                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered Oct 4 '13 at 18:15









                                                                                              Ankit SinghalAnkit Singhal

                                                                                              69468




                                                                                              69468























                                                                                                  0














                                                                                                  In phpstorm + vagrant autoReconnect driver option helped.






                                                                                                  share|improve this answer
























                                                                                                  • got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                                                                                                    – Meetai.com
                                                                                                    Jun 29 '14 at 9:57
















                                                                                                  0














                                                                                                  In phpstorm + vagrant autoReconnect driver option helped.






                                                                                                  share|improve this answer
























                                                                                                  • got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                                                                                                    – Meetai.com
                                                                                                    Jun 29 '14 at 9:57














                                                                                                  0












                                                                                                  0








                                                                                                  0







                                                                                                  In phpstorm + vagrant autoReconnect driver option helped.






                                                                                                  share|improve this answer













                                                                                                  In phpstorm + vagrant autoReconnect driver option helped.







                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Feb 18 '14 at 5:25









                                                                                                  gaRexgaRex

                                                                                                  3,5301735




                                                                                                  3,5301735













                                                                                                  • got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                                                                                                    – Meetai.com
                                                                                                    Jun 29 '14 at 9:57



















                                                                                                  • got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                                                                                                    – Meetai.com
                                                                                                    Jun 29 '14 at 9:57

















                                                                                                  got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                                                                                                  – Meetai.com
                                                                                                  Jun 29 '14 at 9:57





                                                                                                  got: java.sql.SQLException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

                                                                                                  – Meetai.com
                                                                                                  Jun 29 '14 at 9:57











                                                                                                  0














                                                                                                  The resolution provided by Soheil was successful in my case.



                                                                                                  To clarify, the only change I needed to make was with MySQL's server configuration;



                                                                                                  bind-address = **INSERT-IP-HERE**


                                                                                                  I am using an external MySQL server for my application. It is a basic Debian 7.5 installation with MySQL Server 5.5 - default configuration.



                                                                                                  IMPORTANT:




                                                                                                  Always backup the original of any configuration files you may modify. Always take care when elevated as super user.




                                                                                                  File



                                                                                                  /etc/mysql/my.cnf


                                                                                                  Line



                                                                                                  bind-address        = 192.168.0.103 #127.0.0.1


                                                                                                  Restart your MySQL Server service:



                                                                                                  /usr/sbin/service mysql restart


                                                                                                  As you can see, I simply provided the network IP of the server and commented out the default entry. Please note that simply copy and paste my solution will not work for you, unless by some miracle our hosts share the same IP.



                                                                                                  Thanks @ Soheil






                                                                                                  share|improve this answer




























                                                                                                    0














                                                                                                    The resolution provided by Soheil was successful in my case.



                                                                                                    To clarify, the only change I needed to make was with MySQL's server configuration;



                                                                                                    bind-address = **INSERT-IP-HERE**


                                                                                                    I am using an external MySQL server for my application. It is a basic Debian 7.5 installation with MySQL Server 5.5 - default configuration.



                                                                                                    IMPORTANT:




                                                                                                    Always backup the original of any configuration files you may modify. Always take care when elevated as super user.




                                                                                                    File



                                                                                                    /etc/mysql/my.cnf


                                                                                                    Line



                                                                                                    bind-address        = 192.168.0.103 #127.0.0.1


                                                                                                    Restart your MySQL Server service:



                                                                                                    /usr/sbin/service mysql restart


                                                                                                    As you can see, I simply provided the network IP of the server and commented out the default entry. Please note that simply copy and paste my solution will not work for you, unless by some miracle our hosts share the same IP.



                                                                                                    Thanks @ Soheil






                                                                                                    share|improve this answer


























                                                                                                      0












                                                                                                      0








                                                                                                      0







                                                                                                      The resolution provided by Soheil was successful in my case.



                                                                                                      To clarify, the only change I needed to make was with MySQL's server configuration;



                                                                                                      bind-address = **INSERT-IP-HERE**


                                                                                                      I am using an external MySQL server for my application. It is a basic Debian 7.5 installation with MySQL Server 5.5 - default configuration.



                                                                                                      IMPORTANT:




                                                                                                      Always backup the original of any configuration files you may modify. Always take care when elevated as super user.




                                                                                                      File



                                                                                                      /etc/mysql/my.cnf


                                                                                                      Line



                                                                                                      bind-address        = 192.168.0.103 #127.0.0.1


                                                                                                      Restart your MySQL Server service:



                                                                                                      /usr/sbin/service mysql restart


                                                                                                      As you can see, I simply provided the network IP of the server and commented out the default entry. Please note that simply copy and paste my solution will not work for you, unless by some miracle our hosts share the same IP.



                                                                                                      Thanks @ Soheil






                                                                                                      share|improve this answer













                                                                                                      The resolution provided by Soheil was successful in my case.



                                                                                                      To clarify, the only change I needed to make was with MySQL's server configuration;



                                                                                                      bind-address = **INSERT-IP-HERE**


                                                                                                      I am using an external MySQL server for my application. It is a basic Debian 7.5 installation with MySQL Server 5.5 - default configuration.



                                                                                                      IMPORTANT:




                                                                                                      Always backup the original of any configuration files you may modify. Always take care when elevated as super user.




                                                                                                      File



                                                                                                      /etc/mysql/my.cnf


                                                                                                      Line



                                                                                                      bind-address        = 192.168.0.103 #127.0.0.1


                                                                                                      Restart your MySQL Server service:



                                                                                                      /usr/sbin/service mysql restart


                                                                                                      As you can see, I simply provided the network IP of the server and commented out the default entry. Please note that simply copy and paste my solution will not work for you, unless by some miracle our hosts share the same IP.



                                                                                                      Thanks @ Soheil







                                                                                                      share|improve this answer












                                                                                                      share|improve this answer



                                                                                                      share|improve this answer










                                                                                                      answered May 18 '14 at 4:46









                                                                                                      Captain DustyCaptain Dusty

                                                                                                      11




                                                                                                      11























                                                                                                          0














                                                                                                          I was experiencing similar problem and the solution for my case was




                                                                                                          1. changing bind-address = 0.0.0.0 from 127.0.0.1

                                                                                                          2. changing url's localhost to localhost:3306


                                                                                                          the thing i felt is we should never give up, i tried every options from this post and from other forums as well...happy it works @saurab






                                                                                                          share|improve this answer




























                                                                                                            0














                                                                                                            I was experiencing similar problem and the solution for my case was




                                                                                                            1. changing bind-address = 0.0.0.0 from 127.0.0.1

                                                                                                            2. changing url's localhost to localhost:3306


                                                                                                            the thing i felt is we should never give up, i tried every options from this post and from other forums as well...happy it works @saurab






                                                                                                            share|improve this answer


























                                                                                                              0












                                                                                                              0








                                                                                                              0







                                                                                                              I was experiencing similar problem and the solution for my case was




                                                                                                              1. changing bind-address = 0.0.0.0 from 127.0.0.1

                                                                                                              2. changing url's localhost to localhost:3306


                                                                                                              the thing i felt is we should never give up, i tried every options from this post and from other forums as well...happy it works @saurab






                                                                                                              share|improve this answer













                                                                                                              I was experiencing similar problem and the solution for my case was




                                                                                                              1. changing bind-address = 0.0.0.0 from 127.0.0.1

                                                                                                              2. changing url's localhost to localhost:3306


                                                                                                              the thing i felt is we should never give up, i tried every options from this post and from other forums as well...happy it works @saurab







                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered Jul 3 '14 at 18:20









                                                                                                              Saurab DulalSaurab Dulal

                                                                                                              685




                                                                                                              685























                                                                                                                  0














                                                                                                                  I faced this problem also.



                                                                                                                  As Soheil suggested,
                                                                                                                  I went to php.ini file at the path C:windowsphp.ini , then I revised port number in this file.



                                                                                                                  it is on the line mysqli.default_port =..........



                                                                                                                  So I changed it in my java app as it's in the php.ini file,now it works fine with me.






                                                                                                                  share|improve this answer




























                                                                                                                    0














                                                                                                                    I faced this problem also.



                                                                                                                    As Soheil suggested,
                                                                                                                    I went to php.ini file at the path C:windowsphp.ini , then I revised port number in this file.



                                                                                                                    it is on the line mysqli.default_port =..........



                                                                                                                    So I changed it in my java app as it's in the php.ini file,now it works fine with me.






                                                                                                                    share|improve this answer


























                                                                                                                      0












                                                                                                                      0








                                                                                                                      0







                                                                                                                      I faced this problem also.



                                                                                                                      As Soheil suggested,
                                                                                                                      I went to php.ini file at the path C:windowsphp.ini , then I revised port number in this file.



                                                                                                                      it is on the line mysqli.default_port =..........



                                                                                                                      So I changed it in my java app as it's in the php.ini file,now it works fine with me.






                                                                                                                      share|improve this answer













                                                                                                                      I faced this problem also.



                                                                                                                      As Soheil suggested,
                                                                                                                      I went to php.ini file at the path C:windowsphp.ini , then I revised port number in this file.



                                                                                                                      it is on the line mysqli.default_port =..........



                                                                                                                      So I changed it in my java app as it's in the php.ini file,now it works fine with me.







                                                                                                                      share|improve this answer












                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer










                                                                                                                      answered Dec 24 '14 at 14:06









                                                                                                                      PHPFanPHPFan

                                                                                                                      4152931




                                                                                                                      4152931























                                                                                                                          0














                                                                                                                          I know this is an old thread but I have tried numerous things and fixed my issue using the following means..



                                                                                                                          I'm developing a cross platform app on Windows but to be used on Linux and Windows servers.



                                                                                                                          A MySQL database called "jtm" installed on both systems. For some reason, in my code I had the database name as "JTM". On Windows it worked fine, in fact on several Windows systems it flew along.



                                                                                                                          On Ubuntu I got the error above time and time again. I tested it out with the correct case in the code "jtm" and it works a treat.



                                                                                                                          Linux is obviously a lot less forgiving about case sensitivity (rightly so), whereas Windows makes allowances.



                                                                                                                          I feel a bit daft now but check everything. The error message is not the best but it does seem fixable if you persevere and get things right.






                                                                                                                          share|improve this answer




























                                                                                                                            0














                                                                                                                            I know this is an old thread but I have tried numerous things and fixed my issue using the following means..



                                                                                                                            I'm developing a cross platform app on Windows but to be used on Linux and Windows servers.



                                                                                                                            A MySQL database called "jtm" installed on both systems. For some reason, in my code I had the database name as "JTM". On Windows it worked fine, in fact on several Windows systems it flew along.



                                                                                                                            On Ubuntu I got the error above time and time again. I tested it out with the correct case in the code "jtm" and it works a treat.



                                                                                                                            Linux is obviously a lot less forgiving about case sensitivity (rightly so), whereas Windows makes allowances.



                                                                                                                            I feel a bit daft now but check everything. The error message is not the best but it does seem fixable if you persevere and get things right.






                                                                                                                            share|improve this answer


























                                                                                                                              0












                                                                                                                              0








                                                                                                                              0







                                                                                                                              I know this is an old thread but I have tried numerous things and fixed my issue using the following means..



                                                                                                                              I'm developing a cross platform app on Windows but to be used on Linux and Windows servers.



                                                                                                                              A MySQL database called "jtm" installed on both systems. For some reason, in my code I had the database name as "JTM". On Windows it worked fine, in fact on several Windows systems it flew along.



                                                                                                                              On Ubuntu I got the error above time and time again. I tested it out with the correct case in the code "jtm" and it works a treat.



                                                                                                                              Linux is obviously a lot less forgiving about case sensitivity (rightly so), whereas Windows makes allowances.



                                                                                                                              I feel a bit daft now but check everything. The error message is not the best but it does seem fixable if you persevere and get things right.






                                                                                                                              share|improve this answer













                                                                                                                              I know this is an old thread but I have tried numerous things and fixed my issue using the following means..



                                                                                                                              I'm developing a cross platform app on Windows but to be used on Linux and Windows servers.



                                                                                                                              A MySQL database called "jtm" installed on both systems. For some reason, in my code I had the database name as "JTM". On Windows it worked fine, in fact on several Windows systems it flew along.



                                                                                                                              On Ubuntu I got the error above time and time again. I tested it out with the correct case in the code "jtm" and it works a treat.



                                                                                                                              Linux is obviously a lot less forgiving about case sensitivity (rightly so), whereas Windows makes allowances.



                                                                                                                              I feel a bit daft now but check everything. The error message is not the best but it does seem fixable if you persevere and get things right.







                                                                                                                              share|improve this answer












                                                                                                                              share|improve this answer



                                                                                                                              share|improve this answer










                                                                                                                              answered Jan 8 '15 at 2:05









                                                                                                                              thonnorthonnor

                                                                                                                              499721




                                                                                                                              499721























                                                                                                                                  0














                                                                                                                                  I just restarted MySQL (following a tip from here: https://stackoverflow.com/a/14238800) and it solved the issue.



                                                                                                                                  I had the same issue on MacOS (10.10.2) and MySql (5.6.21) installed via homebrew.



                                                                                                                                  The confusing thing was that one of my apps connected to the database fine and the other did not.



                                                                                                                                  After trying many things on the app that threw the exception com.mysql.jdbc.CommunicationsException as suggested by the the accepted answer of this question to no avail, I was surprised that restarting MySQL worked.



                                                                                                                                  The cause of my issue might have been the following as suggested in the answer in the aforementioned link:




                                                                                                                                  Are you using connection pool ? If yes, then try to restart the
                                                                                                                                  server. Probably few of the connections in your connection pool are in closed state.







                                                                                                                                  share|improve this answer






























                                                                                                                                    0














                                                                                                                                    I just restarted MySQL (following a tip from here: https://stackoverflow.com/a/14238800) and it solved the issue.



                                                                                                                                    I had the same issue on MacOS (10.10.2) and MySql (5.6.21) installed via homebrew.



                                                                                                                                    The confusing thing was that one of my apps connected to the database fine and the other did not.



                                                                                                                                    After trying many things on the app that threw the exception com.mysql.jdbc.CommunicationsException as suggested by the the accepted answer of this question to no avail, I was surprised that restarting MySQL worked.



                                                                                                                                    The cause of my issue might have been the following as suggested in the answer in the aforementioned link:




                                                                                                                                    Are you using connection pool ? If yes, then try to restart the
                                                                                                                                    server. Probably few of the connections in your connection pool are in closed state.







                                                                                                                                    share|improve this answer




























                                                                                                                                      0












                                                                                                                                      0








                                                                                                                                      0







                                                                                                                                      I just restarted MySQL (following a tip from here: https://stackoverflow.com/a/14238800) and it solved the issue.



                                                                                                                                      I had the same issue on MacOS (10.10.2) and MySql (5.6.21) installed via homebrew.



                                                                                                                                      The confusing thing was that one of my apps connected to the database fine and the other did not.



                                                                                                                                      After trying many things on the app that threw the exception com.mysql.jdbc.CommunicationsException as suggested by the the accepted answer of this question to no avail, I was surprised that restarting MySQL worked.



                                                                                                                                      The cause of my issue might have been the following as suggested in the answer in the aforementioned link:




                                                                                                                                      Are you using connection pool ? If yes, then try to restart the
                                                                                                                                      server. Probably few of the connections in your connection pool are in closed state.







                                                                                                                                      share|improve this answer















                                                                                                                                      I just restarted MySQL (following a tip from here: https://stackoverflow.com/a/14238800) and it solved the issue.



                                                                                                                                      I had the same issue on MacOS (10.10.2) and MySql (5.6.21) installed via homebrew.



                                                                                                                                      The confusing thing was that one of my apps connected to the database fine and the other did not.



                                                                                                                                      After trying many things on the app that threw the exception com.mysql.jdbc.CommunicationsException as suggested by the the accepted answer of this question to no avail, I was surprised that restarting MySQL worked.



                                                                                                                                      The cause of my issue might have been the following as suggested in the answer in the aforementioned link:




                                                                                                                                      Are you using connection pool ? If yes, then try to restart the
                                                                                                                                      server. Probably few of the connections in your connection pool are in closed state.








                                                                                                                                      share|improve this answer














                                                                                                                                      share|improve this answer



                                                                                                                                      share|improve this answer








                                                                                                                                      edited May 23 '17 at 11:47









                                                                                                                                      Community

                                                                                                                                      11




                                                                                                                                      11










                                                                                                                                      answered Apr 2 '15 at 16:13









                                                                                                                                      dulondulon

                                                                                                                                      62986




                                                                                                                                      62986























                                                                                                                                          0














                                                                                                                                          For Windows :-
                                                                                                                                          Goto start menu write , "MySqlserver Instance Configuration Wizard" and reconfigure your mysql server instance.
                                                                                                                                          Hope it will solve your problem.






                                                                                                                                          share|improve this answer




























                                                                                                                                            0














                                                                                                                                            For Windows :-
                                                                                                                                            Goto start menu write , "MySqlserver Instance Configuration Wizard" and reconfigure your mysql server instance.
                                                                                                                                            Hope it will solve your problem.






                                                                                                                                            share|improve this answer


























                                                                                                                                              0












                                                                                                                                              0








                                                                                                                                              0







                                                                                                                                              For Windows :-
                                                                                                                                              Goto start menu write , "MySqlserver Instance Configuration Wizard" and reconfigure your mysql server instance.
                                                                                                                                              Hope it will solve your problem.






                                                                                                                                              share|improve this answer













                                                                                                                                              For Windows :-
                                                                                                                                              Goto start menu write , "MySqlserver Instance Configuration Wizard" and reconfigure your mysql server instance.
                                                                                                                                              Hope it will solve your problem.







                                                                                                                                              share|improve this answer












                                                                                                                                              share|improve this answer



                                                                                                                                              share|improve this answer










                                                                                                                                              answered May 15 '15 at 6:17









                                                                                                                                              Himanshu NarangHimanshu Narang

                                                                                                                                              71111




                                                                                                                                              71111























                                                                                                                                                  0














                                                                                                                                                  After years having the same issue and no permanent solution this is whats solved it for the past 3 weeks (which is a record in terms of error free operation)



                                                                                                                                                  set global wait_timeout=3600;

                                                                                                                                                  set global interactive_timeout=230400;



                                                                                                                                                  Don't forget to make this permanent if it works for you.






                                                                                                                                                  share|improve this answer




























                                                                                                                                                    0














                                                                                                                                                    After years having the same issue and no permanent solution this is whats solved it for the past 3 weeks (which is a record in terms of error free operation)



                                                                                                                                                    set global wait_timeout=3600;

                                                                                                                                                    set global interactive_timeout=230400;



                                                                                                                                                    Don't forget to make this permanent if it works for you.






                                                                                                                                                    share|improve this answer


























                                                                                                                                                      0












                                                                                                                                                      0








                                                                                                                                                      0







                                                                                                                                                      After years having the same issue and no permanent solution this is whats solved it for the past 3 weeks (which is a record in terms of error free operation)



                                                                                                                                                      set global wait_timeout=3600;

                                                                                                                                                      set global interactive_timeout=230400;



                                                                                                                                                      Don't forget to make this permanent if it works for you.






                                                                                                                                                      share|improve this answer













                                                                                                                                                      After years having the same issue and no permanent solution this is whats solved it for the past 3 weeks (which is a record in terms of error free operation)



                                                                                                                                                      set global wait_timeout=3600;

                                                                                                                                                      set global interactive_timeout=230400;



                                                                                                                                                      Don't forget to make this permanent if it works for you.







                                                                                                                                                      share|improve this answer












                                                                                                                                                      share|improve this answer



                                                                                                                                                      share|improve this answer










                                                                                                                                                      answered Jun 13 '15 at 12:04









                                                                                                                                                      itpp13itpp13

                                                                                                                                                      35215




                                                                                                                                                      35215























                                                                                                                                                          -3














                                                                                                                                                          If you are using local emulator, you have to use IP address 10.0.2.2 instead of localhost to access to your local MySQL server.






                                                                                                                                                          share|improve this answer




























                                                                                                                                                            -3














                                                                                                                                                            If you are using local emulator, you have to use IP address 10.0.2.2 instead of localhost to access to your local MySQL server.






                                                                                                                                                            share|improve this answer


























                                                                                                                                                              -3












                                                                                                                                                              -3








                                                                                                                                                              -3







                                                                                                                                                              If you are using local emulator, you have to use IP address 10.0.2.2 instead of localhost to access to your local MySQL server.






                                                                                                                                                              share|improve this answer













                                                                                                                                                              If you are using local emulator, you have to use IP address 10.0.2.2 instead of localhost to access to your local MySQL server.







                                                                                                                                                              share|improve this answer












                                                                                                                                                              share|improve this answer



                                                                                                                                                              share|improve this answer










                                                                                                                                                              answered Mar 7 '14 at 11:05









                                                                                                                                                              CarlosCarlos

                                                                                                                                                              13




                                                                                                                                                              13















                                                                                                                                                                  Popular posts from this blog

                                                                                                                                                                  MongoDB - Not Authorized To Execute Command

                                                                                                                                                                  How to fix TextFormField cause rebuild widget in Flutter

                                                                                                                                                                  in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith