Yet another MySQL connection issue

YaniMan Source

I have to deploy my java server app to a Debian 8 server. It tries to connect to the MySQL server via unix domain socket or tcp (depending on connection string). It works fine on my Debian 9 development server, but gives (as i think) useless error messages on the live server. I have root access to both servers but not allowed to do much on the live server. As i had version troubles compiling java on D9 and running it on D8, i have installed openjdk-7-jdk and mysql java connector on the D8 from the Debian repo, copied (symlinked) the connector jar to the lib directory of the source, and recompiled the app. Now it starts but when trying to connect to the database, it throws the following errors:

TCP: Connection refused
UDS: File not found (nonexistent file or device) ((the translation may not be correct, sorry))

Both connections (TCP and UDS) works fine from PHP & PDO. Connection strings:

TCP: jdbc:mysql://localhost/<dbname>?user=<user>&password=<pwd>&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&characterEncoding=utf8
UDS: jdbc:mysql:///<dbname>?socketFactory=com.mysql.jdbc.NamedPipeSocketFactory&namedPipePath=/var/run/mysqld/mysqld.sock&user=<user>&password=<pwd>&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&characterEncoding=utf8

dbname, user, pwd and the socket file path are copied and pasted from the working PHP code. Worth noting that i'm not a java expert, i may not know something that should be known using these older libraries. Some source code:

Connection db = DriverManager.getConnection(Settings.sqlConnection.value);
try(Statement stmt = c.createStatement())
    stmt.execute("SET @now = UTC_TIMESTAMP()");

Version info:

Debian 8.7
MySQL server 5.5.53-0+deb8u1
java version "1.7.0_181"
OpenJDK Runtime Environment (IcedTea 2.6.14) (7u181-2.6.14-1~deb8u1)
OpenJDK 64-Bit Server VM (build 24.181-b01, mixed mode)

What am i missing? Why do i get connection refused and missing file error messages while clearly the server is listening and the socket file is there and have the right permissions - and other clients can connect?



answered 5 days ago YaniMan #1

Nevermind, i've got the solution (not much after posting the question and so much after started having the issue... as usual).

UDS: I simply mixed up named pipes with unix domain sockets which are two entirely different implementations of the same concept. JDBC simply can't do UDS. Now i realize that i tested my code on the dev server probably with TCP connection only.

TCP: The server socket was bound to the server's exact address therefore localhost wouldn't work. My narrow thinking about connection refused error completely misguided me.

comments powered by Disqus