This is a replica of my SO question

I have a public accessible Mysql instance and i am trying to access it behind a clients VPN. So, on the VPN I was granted access to the DB, so by doing
mysql -h IP -u user -p
I can connect to it and run queries just fine The problems start when I try to connect to it via a CLI java application. I open the connection like so

Connection source= DriverManager.getConnection("jdbc:mysql://"+getHost()+"/"+getDB()+"?useUnicode=true",

and I get no errors. when i try to run a query like so

rs=source.createStatement().executeQuery("select ...");

I am getting nothing. I have been sitting there waiting and no results comes back nor an error/exception!

The Mysql instance is accepting the connection since I can see the connection when i get the processlist

| Id | User | Host| db | Command | Time | State | Info | +----+------+-----+----+---------------+------+--------+------+
| 9094 | user |ClientIp:58450 | DB | Sleep | 4933 | | NULL |

plus when i get the error log of the db

tail /var/log/mysql/error.log 2019-04-23T14:17:34.286979Z 9175 [Note] Aborted connection 9175 to db: 'db' user: 'user' host: 'ClientIp' (Got an error reading communication packets) 2019-04-23T14:17:46.501602Z 9174 [Note] Aborted connection 9174 to db: 'db' user: 'user' host: 'ClientIp' (Got timeout writing communication packets)

I am starting to think that they network guys on the client side, open up the outgoing ports (3306, so i can connect to the DB) but the incoming port (which is random as far as I know and remember from my college network cource). This must be confirmed by the host record of process list which is IP:58450. This is the listening port of the client, right. So if this is closed the connection would stay open, waiting for an incoming message, but the message itself would be blocked(since the port is blocked)
First, is there a way to validate this so I can know for sure that this is the problem with this? Just to have something to talk to the network people over there.

From what i know, you cant specify a (range of) port for the client to talk to. What can you do in cases where ports are blocked by firewalls?

Thanks in advance. Ilias

When running netstat while connected to Mysql I see this

netstat -a |grep mysql
tcp 0 0 client:58744 MySqlRemote.e:mysql ESTABLISHED

while when I connect using java I get

tcp6 0 0 client:58748 MySqlRemote.e:mysql ESTABLISHED

so, it seems that the connection is ok in both cases. The only obvious difference is tcp - tcp6 on the two records. So I thought that the problem might be on using IP6 in java. I tried to disable it by using System.setProperty("java.net.preferIPv4Stack" , "true"); and disabling IP6 on the VM alltogether by editing the /etc/hosts file. The result is that now using netstat i see IP4 is been used, but the query is still not responding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.