MYSQL: Communications link failure

I am running MySQL and lucee-nginx 5.3 on docker. Both services are running fine except I can’t connect to MySQL (ie. create datasource) from lucee admin.
I have used phpmyadmin, SQL workbench to connect to the MySQL server and I was able to. But Lucee keeps saying Communications link failure. The driver has not received any packets from the server. What can be that issue?

I will appreciate any assistance.

Lucee.runtime.exp.DatabaseException: 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.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:833)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at lucee.runtime.db.DataSourceSupport._getConnection(DataSourceSupport.java:135)
at lucee.runtime.db.DataSourceSupport.getConnection(DataSourceSupport.java:103)
at lucee.runtime.db.DatasourceConnectionPool.loadDatasourceConnection(DatasourceConnectionPool.java:157)
at lucee.runtime.db.DatasourceConnectionPool.getDatasourceConnection(DatasourceConnectionPool.java:118)
at lucee.runtime.db.DatasourceManagerImpl.getConnection(DatasourceManagerImpl.java:75)
at lucee.runtime.tag.Query.executeDatasoure(Query.java:1119)
at lucee.runtime.tag.Query._doEndTag(Query.java:699)
at lucee.runtime.tag.Query.doEndTag(Query.java:565)
at lucee.runtime.functions.query.QueryExecute.call(QueryExecute.java:86)
at index_cfm$cf.call(/index.cfm:5)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1000)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:923)
at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:217)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2457)
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2447)
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2418)
at lucee.runtime.engine.Request.exe(Request.java:44)
at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1179)
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1125)
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:228)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:764)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1723)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)

Hi @wicfasho welcome to our Lucee community.

Really can’t say. but I think had something similar with MariaDB a while ago, but that wasn’t on docker. I think it had something to do with the binding address in mysql and how the machine was resolving the localhost in that ocasion, but I can’t tell for sure anymore.

There are many posts and solutions over the internet about this communication failure related to JDBC connectors, but all tell about very different issues and solutions. I’ve found one that I think would be the first I’d try:

In case you are changing settings with mysql’s IP addresses, make sure you are not letting the connection exposed to the public internet.

Maybe another one who is running Lucee on docker might have a better advice for you, buf for now I’d try changing the binding address first to see if it works.

Please keep us updated!

please always mention which version(s) or lucee, drivers etc you are using :slight_smile:

I would try to connect via command line manually first.

from your docker image as root

mysql -u YOURUSERNAME -pYOURPASSWORD

Use the same username and password as the lucee instance that you’re trying to connect with.
If you are.

If you connect, then it maybe the ip binding in docker is using the external interface not the internal interface. as long as its NOT production you could run the following.

in mysql with the correct permissions (root)

SHOW GRANTS FOR 'YOURUSERNAME'@'localhost';

You should get something like this
+---------------------------------------------------------------------------+
| Grants for username@localhost                                             |
+---------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'YOURUSERNAME'@'localhost' IDENTIFIED BY PASSWORD 'YOURPASSWORD' |
| GRANT ALL PRIVILEGES ON `YOURDATABASE`.* TO 'YOURUSERNAME'@'localhost'              |
+---------------------------------------------------------------------------+

If you have something like that, then make sure in your doctor host file, you have defined LOCALHOST in /etc/hosts as 127…0.0.1 localhost LOCALHOST YOURMACHINENAME

If you are using IP^
::1 localhost LOCALHOST YOURMACHINENAME

Note: Linux even on docker make sure you are using lower case, I add localhost in both all CAPS and lowercase on linux boxes as developers make mistakes

If lucee is using the exernal ip and trying to connect to the localhost, then you would need to run in mysql

UPDATE YOURDATABASE.db SET Host='%' WHERE Host='YOURIP"' AND User='YOURUSERNAME';
2 Likes

i have tested with all versions of the MySQL extension and I mentioned the lucee-nginx image version I am using.

Thanks.
Am i running mysql -u YOURUSERNAME -pYOURPASSWORD on the lucee container? because mysql installed in the lucee cotainer. However i ran it on the mysql container and it worked fine.

Thanks to everyone who tried to support me here.
The issue was a very minor issue and an oversight. I didn’t add both containers on the same network on my docker-compose file.
After doing that, I was able to speak to MySQL DB with the service name like this:

jdbc:mysql://mysql-service:3306/db_name?.......

mysql-service is the container name

I also didn’t need to expose the port on the host machine or bind IP since the containers could speak with each other.

2 Likes