Quantcast

Production - cannot connect to MySQL

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Production - cannot connect to MySQL

John Moore
First off, I've been connecting Grails apps to MySQL elsewhere for a while now, so this is unlikely to be a complete newbie error...

I'm trying to deploy a Grails application onto a server over which I have only partial control  - for example, I don't appear to have permissions to stop and start mysql, and I cannot edit or even read the my.cnf file, and I have a constrained Tomcat environment (which I have not set up). The app (which runs fine in the prod environment with MySQL on my development machine) doesn't start up successfully. After a long wait where nothing seems to be happening, I get the stracktrace of messages about being unable to create the sessionFactory, etc., towards the bottom of which is this:

Caused by: 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 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:2332)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	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:579)
	at java.sql.DriverManager.getConnection(DriverManager.java:190)
	... 6 more
Caused by: java.net.ConnectException: Connection timed out
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
	at java.net.Socket.connect(Socket.java:579)
	at java.net.Socket.connect(Socket.java:528)
	at java.net.Socket.<init>(Socket.java:425)
	at java.net.Socket.<init>(Socket.java:241)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
	... 16 more


What seems to be occurring is that Tomcat is completely unable to create a connection with the MySQL server. My data source setting is completely normal:

dataSource {
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        username = "myusername"
        password = "mypassword"
        dbCreate = "update"
        url = "jdbc:mysql://localhost :3306/mydb"
        dialect = org.hibernate.dialect.MySQLInnoDBDialect

}

I tried changing localhost to 127.0.0.1, thinking this might be the answer, but it wasn't. I can ssh in and use a mysql client to connect to the database with these credentials without a problem, so it's not a credentials issue. The real password (not shown above) contains an '=' and a '?' but I can't see that this could be the problem, because I'm not getting an authorization error, I'm just not getting any communication with the server.

Has anyone come across this before? Why might my MySQL server be effectively invisible to my web application, when I can access it fine via a mysql client?

This is Grails 2.0.4, using mysql-connector-java-5.1.18-bin.jar, on Tomcat 7.0.28 on CentOS.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Production - cannot connect to MySQL

Harlan H. Bloom
This may not be the problem, but why is there a space after localhost in the URL?


From: "John Moore" <[hidden email]>
To: [hidden email]
Sent: Saturday, July 14, 2012 6:42:16 AM
Subject: [grails-user] Production - cannot connect to MySQL

First off, I've been connecting Grails apps to MySQL elsewhere for a while
now, so this is unlikely to be a complete newbie error...

I'm trying to deploy a Grails application onto a server over which I have
only partial control  - for example, I don't appear to have permissions to
stop and start mysql, and I cannot edit or even read the my.cnf file, and I
have a constrained Tomcat environment (which I have not set up). The app
(which runs fine in the prod environment with MySQL on my development
machine) doesn't start up successfully. After a long wait where nothing
seems to be happening, I get the stracktrace of messages about being unable
to create the sessionFactory, etc., towards the bottom of which is this:



What seems to be occurring is that Tomcat is completely unable to create a
connection with the MySQL server. My data source setting is completely
normal:

dataSource {
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        username = "myusername"
        password = "mypassword"
        dbCreate = "update"
        url = "jdbc:mysql://localhost :3306/mydb"
        dialect = org.hibernate.dialect.MySQLInnoDBDialect

}

I tried changing localhost to 127.0.0.1, thinking this might be the answer,
but it wasn't. I can ssh in and use a mysql client to connect to the
database with these credentials without a problem, so it's not a credentials
issue. The real password (not shown above) contains an '=' and a '?' but I
can't see that this could be the problem, because I'm not getting an
authorization error, I'm just not getting any communication with the server.

Has anyone come across this before? Why might my MySQL server be effectively
invisible to my web application, when I can access it fine via a mysql
client?

This is Grails 2.0.4, using mysql-connector-java-5.1.18-bin.jar, on Tomcat
7.0.28 on CentOS.

--
View this message in context: http://grails.1312388.n4.nabble.com/Production-cannot-connect-to-MySQL-tp4631554.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Production - cannot connect to MySQL

John Moore
Harlan H. Bloom wrote
This may not be the problem, but why is there a space after localhost in the URL?
Just a typo on my part in my message. It's not there in the actual config file.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Production - cannot connect to MySQL - SOLVED

John Moore
Turned out to be a firewall problem in the end. The hosting people for some reason had opened up port 3306 to the outside world but closed it to traffic from the same machine, which really hadn't struck me as a possibility. It has now been corrected.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: Production - cannot connect to MySQL

Ryan Vanderwerf
In reply to this post by John Moore
Could be a shot in the dark but is your Linux install perhaps running SELinux, and it's blocking Tomcat's ability to use port 3306? I see you can set it up to give certain apps access to certain ports via context's?

Ryan
________________________________________
From: John Moore [[hidden email]]
Sent: Saturday, July 14, 2012 6:42 AM
To: [hidden email]
Subject: [grails-user] Production - cannot connect to MySQL

First off, I've been connecting Grails apps to MySQL elsewhere for a while
now, so this is unlikely to be a complete newbie error...

I'm trying to deploy a Grails application onto a server over which I have
only partial control  - for example, I don't appear to have permissions to
stop and start mysql, and I cannot edit or even read the my.cnf file, and I
have a constrained Tomcat environment (which I have not set up). The app
(which runs fine in the prod environment with MySQL on my development
machine) doesn't start up successfully. After a long wait where nothing
seems to be happening, I get the stracktrace of messages about being unable
to create the sessionFactory, etc., towards the bottom of which is this:



What seems to be occurring is that Tomcat is completely unable to create a
connection with the MySQL server. My data source setting is completely
normal:

dataSource {
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        username = "myusername"
        password = "mypassword"
        dbCreate = "update"
        url = "jdbc:mysql://localhost :3306/mydb"
        dialect = org.hibernate.dialect.MySQLInnoDBDialect

}

I tried changing localhost to 127.0.0.1, thinking this might be the answer,
but it wasn't. I can ssh in and use a mysql client to connect to the
database with these credentials without a problem, so it's not a credentials
issue. The real password (not shown above) contains an '=' and a '?' but I
can't see that this could be the problem, because I'm not getting an
authorization error, I'm just not getting any communication with the server.

Has anyone come across this before? Why might my MySQL server be effectively
invisible to my web application, when I can access it fine via a mysql
client?

This is Grails 2.0.4, using mysql-connector-java-5.1.18-bin.jar, on Tomcat
7.0.28 on CentOS.

--
View this message in context: http://grails.1312388.n4.nabble.com/Production-cannot-connect-to-MySQL-tp4631554.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...