Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to database through SSH using DataGrip

To connect and set up properly with a command line, I "simply" have to do:

  1. ssh <MY_USERNAME>@<URL> -L 1139:arcade:139
  2. Enter <MY_PASSWORD>
  3. psql -h postgres
  4. \c ift2935
  5. set search_path to inscriptions_devoir;

However, I've been tempted to use a more complex tool than the command line to explore the database and try out different SQL commands. Being a fan of JetBrains, I've decided to try out DataGrip.

I have indeed read the actual help page but it doesn't provide me with the information I need.

I lack the understanding of the jargon to know the correspondance, in terms, between the different lines I had to enter and the actual field-names that I am supposed to enter in DataGrip.

DataGrip connection

My question is quite simple: what and where do I type the stuff ?

like image 419
payne Avatar asked Feb 20 '19 04:02

payne


1 Answers

I faced this issue too. So want to explain others how i managed to do it. lets say for example your remote server ip address is 192.128.11.120. Most of the time while tunneling the localhost/127.0.0.1 is used as the host ip address as in such scenarios the localhost ip is set as the bind address in the mysql config.

Here is the step by step guide on setup to connect to MySQL using SSH tunnel.

1 - Go to SSH/SSL tab and select 'Use SSH tunnel'

enter image description here

2 - Click and do shift+enter or click three dots [...] to open SSH Configurations. From there click + sign to add a new configurations. Fill the form with your remote server ssh configurations.

  • If you are using just one ssh key pair select 'OpenSSH config and authentication agent' as Authentication type.ssh key pair select following
  • If you are using more than one key pair or want to use specific file select 'Key pair (OpenSSH or Putty)' as the Authentication type and select the private key file you used to connect to the remote server as the Private key file.

After that click 'Test Connection' to test whether SSH configuration is correct. If it works Click 'Apply' and 'OK' to save it.

enter image description here

Now SSH is configured for DataGrip.

enter image description here

3 - Go to 'General' Tab to add the MySQL related entries. One thing to keep in mind is that most of the time the bind address is set to localhost/127.0.0.1 in MySql to make it secure on the remote servers to enable only ssh connections. In such cases the remote ip(in this case 192.128.11.120) wont work. So, use 127.0.0.1. Click test connection to check whether the MySQL connection works over SSH.

enter image description here

4 - If it works, Click 'Apply' and 'OK' to save it.

like image 68
aimme Avatar answered Sep 27 '22 22:09

aimme