0

I have a WordPress site hosted in Kinsta.

I'm trying to connect to its MySQL database remotely from PhpStorm using SSH.

The SSH connection is connected successfully, but when I try to connect to the main DB, I get the following error:

[08S01]
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.
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

I tried contacting Kinsta Support but they don't have any proper answer for this.

Please Note: If I connect to the same DB from MySQL Workbench, it works fine. This is only when I connect from PhpStorm!

Can anybody please help me?

Virtua Creative
  • 2,025
  • 1
  • 13
  • 18

2 Answers2

1

I found the solution. I thought it might be helpful for anyone facing the same issue.

Here are the steps;

In order for a PHP Storm to communicate directly with a database, it would need to have a port forwarding set for the SSH tunnel that is being used.

You would need to bind a port site's port to a local port and test the connection manually

You could open two terminals in PHP Storm. In the first one, you could run the following command and enter the SSH password

ssh -L 8888:127.0.0.1:3306 SSHUSERNAME@SITEEXTERNALIP -p SSHPORT -NnT

Make Sure you replace SSH USERNAME, SITE EXTERNAL IP, and SSHPORT with proper details show in Kinsta Dashboard respectively.

Once you've successfully connected to SSH in the first one, open the second tab & run nc command

nc 127.0.0.1 8888

If this works, You could use the connection tunnel IP (127.0.0.1) and connection tunnel port (8888) in your DB connection settings when using SSH tunnel when connecting to the DB via PHP Storm.

DB SETTINGS after NC COMMAND

  • 1
    PhpStorm supports SSH already (so you do not need to so anything outside of it). Have you tried that? The SSH/SSL tab on your screenshot? It will establish the SSH tunnel and connect to such remote DB using that. https://www.jetbrains.com/help/phpstorm/configuring-ssh-and-ssl.html#ssh – LazyOne Jan 10 '21 at 15:03
  • Since PhpStorm/DataGrip establish connection to a database via TCP/IP, it needs exact port or port range to connect to. So it obvious, that you need port forwarding and you can do it through SSH/SSL tab. – Vasilii Chernov Jan 12 '21 at 12:49
0

For a Kinsta DB, try connecting to port 3307, which is a C2S port forward for 3306. This worked for me.

127.0.0.1:3307
fortuneRice
  • 4,214
  • 11
  • 43
  • 58