Intellij IDEA ssh tunnel to datasource - mysql

I'm trying to view my remote database running on digital ocean droplet as data source in Intellij IDEA.
ssh tunnel settings
general database settings
I accessed the database from Sequel Pro through ssh so I believe it is set correctly on the server side.
When I test the connection it says: Connection refused by foreign host.
What have I done wrong?
The ip is correct and the passwords and ssh keys as well, I'm certain of that.

usually the ssh port is 22, if you haven't it customized.
If this tunnel is successful, you can connect against your database with the given port.
Check your screenshot. It shows 3306 for the ssh tunnel.

Related

Access Lightsail Instance's database with MySQL Workbench

I have an Amazon Lightsail Ubuntu multi WordPress site set up with bitnami stack.
I'm looking for a way to access the Instance's database on Amazon Lightsail with MySQL Workbench remotely.
Please note that I do not have a seperate Lightsail database, as I'm trying to do things as cheaply as possible at the moment. So the following guide is not applicable to me.
Connecting to your MySQL database in Amazon Lightsail
According the wp-config.php MySQL database is using localhost:3306
I have static IP address 3.230.xxx.xxx. I have taken the DB username and password from the wp_config.php file.
I've entered the details.
I wonder if anybody else has managed to connect to an Instance's database, rather than a seperate database.
If this is not possible I wonder if there are any suggestions as how to best access this Instance's database remotely.
Found the answer using a similar youtube video which is used to connect to phpMyAdmin.
https://www.youtube.com/watch?v=9VdcQLDmYII
Basically you need to use Putty SSH tunneling in order to connect to the MySQL instance
First I added a new connection in Putty, make sure port 22 is open on
the LightSail firewall
Go to the Connection -> SSH -> Auth tab on the right hand side menu
Enter your SSH key which is downloaded from the Lightsail dashboard,
it will need to be converted in the standard recognised by putty
Go to Connections -> Data tab on the right hand side menu. Add a new
forwarded port we are forwarding localhost:3306 on the server to a
port on our machine 2222
Start the connection via Putty.
Now in MySQL WorkBench go to the connection to database windows.
Enter the port 2222 I entered the DB user and Password from
wp-config.php file and was able to successfully connect.
Also found a second method
Within the MySQL Workbench you can change the connection method to `Standard TCP/IP over SSH'. Gave the SSH key and the relevant details on connection was accepted
Here is what you need to remotely connect MySQL on Lightsail.
https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-connecting-to-your-mysql-database
There are 3 steps:
get the endpoint link
enable public mode
configure MySQL workbench
Yes I have - after a marathon tech support session with AWS :)
Although the Lightsail firewall may say port 3306 is open, the server instance itself may have its own firewall settings which close it. On my case teh AMI that was used to set up the instance was configured that way
I my case it was Ubuntu but here is the summary of the advice I got from AWS--
We have connected to the instance via SSH using the user-name 'xxxxxx' from terminal.
--
ssh -l xxxxx 34.xxx.xxx.221
Checked and confirmed that mysql is running on the instance.
systemctl status mysql
Confirmed the port on which mysql is running.
netstat -plnae | grep 'pid'
Checked the 'ufw' firewall rules and noticed that 3306 is not allowed.
ufw status
Opened the port 3306 on ufw firewall
ufw allow 3306
After performing these steps you were able to establish connection to your database
hth

Connecting to Remote MySQL DB over ssh with workbench

I'm trying to connect to a remote DB with MySQL Workbench over SSH. The remote DB I'm trying to connect to has firewall which is private key protected (I have coverted this to OPEN SHH). I keep getting an error when I try to connect, I'm just a little confused on what is the information of the DB I should be using. I consistently see people use localhost and the DB changed intermittadely at the same point in different questions. My set up is currently that I have to connect to the server of the firewall(check) now there are multiple VMs running I wish to connect to e.g. 192.1.91.0. I have also a port set up to this on putty( I don't know if this is relevant) on localhost 5000. When I try to connect using 192.1.91.0 port 3306 or localhost 5000. I get the same error. Can anyone help. Attached is an image of the information I put into workbench
I think there are a few misunderstandings here. A firewall is not protected by a keypair. An SSH connection is. The firewall only filters network traffic using specific rules (e.g. only let it pass for enabled network ports). When you use an SSH connection you have to use the MySQL address as seen from the remote SSH connection end. That means if the MySQL server runs on the same machine as the SSH server (which is what you connect to when you use an SSH tunnel) then the address is localhost (or the IPv4/IPv6 loopback address). See my video about connection creation and troubleshooting on Youtube for more details.
To connect workbench with a private database you will need a 'jump host' also called 'bastion host' which can be any EC2 instance in a public subne in same VPC as database.
Follow Below Steps:
Open the security group attached to the database, and add new rule as below:-
Type:MYSQL/Aurora, Protocol:TCP, PortRange:3306,
Source:securitygroupofEC2 (you can all security group by entering
'sg-')
Open the security group attached to the EC2, and make port 22 is open. If not, add a new rule as below:-
Type:SSH, Protocol:TCP, PortRange:22, Source:MY IP
Open Workbench, Click New connection
- Standard TCP/IP over SSH
- SSH Hostname : < your EC2 Public IP > #34.3.3.1
- SSH Username : < your username > #common ones are : ubuntu, ec2-user, admin
- SSH KeyFile: < attach your EC2 .pem file>
- MYSQL Hostname: <database endpoint name> #mydb.tbgvsblc6.eu-west-1.rds.amazonaws.com
- MYSQL Port: 3306
- Username : <database username>
- Password: <database password>
Click 'test connection' and boom done!!
If the MySQL Server is configured to accept remote connections, you can use the servers IP address, but then you don't need to connect over ssh. Once you choose connect over ssh, the workbench creates a portforwarding using the ssh credentials to the specified server. So you have to use localhost as MySQL hostname. Due to the portforwarding, the request will be forwarded to your remote machine. In short: As far as I understand your question, you have to use localhost.

Workbench migration via ssh - how to set up a tunnel

I try to migrate MSSQL (local machine) to MYSQL (Amazon Web Services) usin Workbench. I can connect to both databases. However when I migrate I get this error:
Mysql connections through SSH are not supported in this version...
Well, I found this in documentation:
A workaround is to set up an encrypted tunnel, and then treat the MySQL target as a standard TCP (unencrypted) connection.
But I don't know how to set up a tunnel. Does anyone can help?
Okay, if I'm understanding this correctly, I think I'd prefer to set up a tunnel in Putty. I don't have a solid grasp of how MySQL Workbench works (I'm assuming its analogous to SSMS), but I have used maaany SSH tunnels in my day. Here are some basic instructions:
http://www.electrictoolbox.com/putty-create-ssh-port-tunnel/
You'll want to create a local tunnel from any port you choose (although I'd go with the MySQL default 3306) to the destination of 127.0.0.1:3306. Be sure to click add and save your session settings in Putty.
Open the SSH connection to the AWS machine. Try to connect to your MySQL instance through 127.0.0.1:3306. This should allow you to pull from your local SQL Server and send data to your AWS instance (through the tunnel, 127.0.0.1:3306 of course).
Hope this helps. Let me know if this doesn't solve your issue.
If you have Amazon ec2:
On Windows machine connect using putty via ssh:
In session host name (user#public_ip_address)
Connection -> SSH -> Tunnels (Source port: 3306 OR choose free one) AND (Destination 127.0.0.1:3306)
You can check if tunnel was establihed in event log (right click on terminal bar)
In Workbench now you can use TCP/IP without SSH.
Thanks guys!

MySQL Server Refusing Local Connections Over SSH Tunnel

I have a remote Windows server with MySQL and Cygwin (enabling remote SSH connections). When I connect from a local instance of Workbench (i.e. with Workbench handling the tunnel), via SSH as root, I have no problem connecting to the remote database.
I have a need to set up my own tunnel because I have another app that needs MySQL access. I chose to use Putty, and had only partial success.
I can connect (using Workbench as a test client) through my tunnel, localhost:3307, which I have forwarded to myremoteserver.no-ip.com:3306, ONLY if I have the remote root user there set to accept connections from all hosts (%), AND/OR the actual IP of the server.
If I restrict root to 127.0.0.1 (as it should be) I get the error Host x.x.x.x is not allowed to connect to this MySQL server where x.x.x.x is the actual address of the remote server!
Somehow, using Putty to make the tunnel isn't presenting me as a local connection. But instead as a remote connection, even though the remote IP is the IP of the remote server
My Question: How can I set up putty to mimic the way Workbench successfully makes tunnel connections?
Note: All my connections to the remote IP are via a no-ip address. This works when Workbench opens the tunnel. Also my server is run within the AWS EC2 ecosystem.
My current Putty connection is to the no-ip address and tunneling settings are Source:3307, Destination: myremoteserver.no-ip.com:3306, Local and Auto.
Edit: I have also tried 127.0.0.1:3306 as the destination address in the Putty tunnel settings and got the same result.
My current Putty connection is to the no-ip address and tunneling
settings are Source:3307, Destination: myremoteserver.no-ip.com:3306,
Local and Auto.
You want to restrict the remote instance of mysql to only accept connections on the localhost interface, so your tunnel should forward to the remote host's localhost interface instead of its network interface. Change the tunnel's destination address to 127.0.0.1 instead of the server's name.

connect and fetch remote MySQL server from Mac

I ma following this tutorial on how to connect to a remote MySQL server, however It seems the command doesn't work and often results in Operation timed out when trying to connect to the server:
ssh mysql.xxxxx.com
I can connect directly from my hosting account but not through the Shell on my Mac OS.
There may be a firewall or other network security device in place that prevents you from being able to connect from your Mac. Also, it is possible that the MySQL server is not configured to allow inbound network connections.
You might ask your hosting provider if they filter access to the MySQL port (default is 3306), or if your host is pre-configured with a firewall, and you might check your MySQL configuration file to ensure it is listening for inbound connections.
When you ssh into a remote server, and you do not specify a user name, ssh defaults to your current user.
bobs-macbook-pro:~ bob$ ssh server.acme.com
is the same as:
bobs-macbook-pro:~ bob$ ssh bob#server.acme.com
Try using your username when 'sshing' into the remote mysql machine.
There are two ways to specify your username, either one should work.
1. bobs-macbook-pro:~ bob$ ssh bob#server.acme.com
2. bobs-macbook-pro:~ bob$ ssh server.acme.com -l bob