0

We are using aws spot instance for dev code testing and as I am new to this environment dont have all understanding yet.

I am able to connect to the mysql using terminal by following below steps

ssh -i ~/.ssh/id_rsa.pub ec2-user_name@{NAT IP Address}
ssh {private ip address}
mysql -u{mysql_suername} -p{mysql_pwd} -hdb{IP Address}

Now I need to try some db changes to improve mysql select query performance so for that I am trying to connect and access Mysql from AWS ec2 spot instance using java code.

I am using following command to create tunnel

ssh -L [listening port]:[REMOTE_MYSQL_HOST]:[REMOTE_MYSQL_PORT] [SSH_USER]@[SSH_HOST]

and following is simple java code to access after connecting to tunnel Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection( "jdbc:mysql://privateIPAddress:3307/dbname","username","pwd"); Statement stmt= conn.createStatement();

#But I am getting below error

com.mysql.cj.jdbc.exceptions.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.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:836)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: 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:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    ... 22 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:67)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:63)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:45)
    at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:538)

I can see there are solution to update my.cnf file for bind-address etc but I dont have permission to update the same file.

stackUser
  • 545
  • 3
  • 9
  • 21

0 Answers0