Connecting to a MySQL database using a socket file

I've configured DataGrip to SSH into a Linux box and pointed it to a MySQL database accessible locally, but I need to be able to talk to it via a socket file. Is there any way to accomplish this in DataGrip currently or is this use not supported?

5 comments
Comment actions Permalink

Hi,

DataGrip works over TCP using JDBC driver. Communication using socket file is not supported.

Thank you.

-1
Comment actions Permalink

Sockets may be (in some situations) required to connect to Google Cloud SQL. Any plans to support that?

6
Comment actions Permalink

I need to connect to MySQL over socket because MAMP doesn't use the default socket

0
Comment actions Permalink

Just got this to work, so since this shows up in a google search I'll post the instructions here:

(This was done with DataGrip 2019.2 running on Ubuntu 19.10)

 

Download an up-to-date version of junixsocket https://github.com/kohlschutter/junixsocket

The Ubuntu package is currently 2.04, and did not work for me. The latest at time of writing (2.3.1) did work.

Extract junixsocket somewhere (doesn't matter, just needs to be accessible to DataGrip.)

In DataGrip's  Data Sources and Drivers Window, select the MySQL driver. Under 'Driver Files', click the + button and select:

junixsocket-mysql-2.3.1.jar

junixsocket-core-2.3.1.jar

junixsocket-common-2.3.1.jar

junixsocket-native-common-2.3.1.jar

from wherever you extracted them.

 

Add a new MySQL datasource, and under 'Advanced':

set 'socketFactory' to 'org.newsclub.net.mysql.AFUNIXDatabaseSocketFactory'

and add 'junixsocket.file' with the path to our unix socket.

 

OR - You can duplicate the MySQL Driver, give it a name like 'MySQL - Unix Socket' and set the socketFactory parameter on the copied driver.

This means you don't have to set it on each Data Source (if you have many).

 

As for the original poster's forwarding over SSH part - you'll have to do that with an SSH command outside DataGrip, as there doesn't seem to be anyway to forward a Unix socket or set custom options on the DataGrip SSH page.

1
Comment actions Permalink

Since I've reached this via Google, I'd like to confirm that the approach above also works for PostgreSQL, I've just configured access to Gitlab's GDK Unix Socket PostgreSQL in RubyMine.

Follow the relevant instructions on the project: https://kohlschutter.github.io/junixsocket/dependency.html

1

Please sign in to leave a comment.