Connect to remote db with ssh tunneling in DBeaver - mysql

I know this question was already asked before (like here), but still I could not find a solution and those posts are quite old.
So I am able to connect to the remote db with an ssh connection and then use the command line like this:
// Putty SSH Connection
host: ssh.strato.de
port: 22
username: xxxxxxx
password: xxxxxxx
// connect to mysql with terminal
mysql -h rdbms -u xxxxxxx -p xxxxxxxx
If I try the same with ssh-tunneling in DBeaver I get an connection error
The ssh-tunneling itself seems to work. If I use the same credentials as above and press "Test tunnel configuration" I get a success message.
I tried several other options for port and host (localhost, rdbms.strato.de, etc), which I found via mysql show variables; show processlist; show user();, but none of them worked.
The Strato Support told me that I can only connect to the db internally with phpmyadmin or remotely wiht putty and mysql, but since the last method is working, shouldn't ssh-tunneling also work?

Dbeaver - Database connection using SSH Tunnel
Open dbeaver
Click on "New Database Connection", in the following "main" window enter the MySQL server host relative to the SSH server, and MySQL running port, my setting is default (localhost, 3306)
specify MySQL user to connect with and user password.
In the "SSH" part, specify the SSH host, port, user also the authentication method used, like SSH private key
Test connection and use.

On shared hosting setups (e.g. IONOS) there might be a restriction when trying to connect to MySQL from external client
https://www.ionos.com/help/hosting/troubleshooting-mysql-databases/connection-and-access-problems-with-mysql-databases/

Related

Can't connect to digital ocean LEMP stack MySql via Workbench (or any gui) but CAN connect via terminal mysql cmd

I have tried suggestions in what seems like every post about this topic and none of them have worked for me, so I'm posting my own in case anyone spots anything that I missed.
I'm migrating a wordpress site into a LEMP (ubuntu, apache) stack instance on Digital Ocean, and I need temporary access to the database via MySQL Workbench or something similar on my local machine. I'm planning to turn it off once the migration is done. However I am having a very weird issue I can't figure out the cause for.
If I attempt to sign into the sql instance using
mysql -u user -h my.ip.address -p
I can get access from my local machine just fine.
I can also SSH into the server itself via terminal just fine, I have it set up in my ssh config file using the same ip address and the same user and ssh key i'm attempting to use for my workbench connection.
However doing the same via an SSH connection on workbench I constantly get the error:
Authentication failed, access denied.
Failed to connect to MySql at my.ip.address:3306 through ssh tunnel at user#127.0.0.1 with user mysqluser
Things I've done to attempt to rectify this:
set bind-address in mysql config to 0.0.0.0 on the server and restarted server's mysql
set bind-address in mysql config to my.ip.address on the server and restarted
allowed tcp connection
allowed connection via ufw firewall to 3306 and 33060 ports
created a mysql user with all privileges granted for 'localhost', '%', and '0.0.0.0' hosts
tried sshing in as root user
tried using the root user for the mysql user
I am probably missing some things on that list as I feel like I've tried a million things already!
I even have a different server on a LAMP stack (not LEMP) that I set up a few days ago and was able to gain access to the mysql db on workbench by following the same steps, and even attempted backtracing and copying what I did on the LAMP server, but no go.
I checked to see the netstats of the mysql instance and match the port and the ip and that didn't work, I made sure the port of the SSH was correct, nothing is working.
Does anyone have any tips? I've been using all of the "allow remote mysql connection on digital ocean" articles and questions i can find but nothing is working.
Here is my Workbench connection config at the moment but i have tried what feels like every iteration of it i could think of (re users, passwords, IP addresses, and ports)
SSH Hostname: my.ip.address
SSH Username: user
SSH Password: user-password (also tried empty, since i have a key)
SSH Key File: same key file i use to ssh on terminal
Mysql Hostname: 127.0.0.1 (also tried my.ip.address)
MySql Server Port: 3306 (also tried 33060)
Username: MySqlUser
Password: MySqlUser-Password (works when connecting to mysql via terminal)

Pentaho JNDI ssh tunneling Data Integration MySQL

I am trying to access a database server using SSH tunneling, credentials are fine, as i have tested this on MYSQL GUI Client using SSH Tunneling option, i have also just tested this using command line and command line connection to server is also working perfectly using below commands on two command line terminals:
ssh root#192.168.1.1 -L 3307:localhost:3306
mysql -h localhost -P 3307 -u qstats -pPassw0rd stats
But when i try to connect to the database server using pentaho it gives error as
Access denied for user 'stats'#'localhost' (using password: YES)
I then used JNDI and gave the credentials there, but still it does not work, my JNDI settings are as follow:
Asterisk/type=javax.sql.DataSource
Asterisk/driver=com.mysql.jdbc.Driver
Asterisk/user=qstats
Asterisk/password=Passw0rd
Asterisk/url=jdbc:mysql://localhost:3307/stats
Please if someone can help?
You need to initiate the SSH connection separately using CMD to the database server and then try to connect using PDI, and connection will be successful. BUT JNDI still don't work, only direct connection works.

Unable to access server database schemas in mySQL Workbench

So I'm working in a team and my computer in particular is running into issues that other people's computers aren't running into, so none of us know how to diagnose the issue. I am running on a Mac with El Capitan. These are the steps I took to connect and access the server database:
SSH into server's terminal:
ssh -i ~/.ssh/your_private_key username#serverIP
Port forwarding through ssh:
ssh -L 3306:localhost:3306 -i ~/.ssh/your_private_key username#serverIP
Error: bind: Address already in use
I go into System Preferences > mySQL > stop mySQL server instance
I go into mySQL workbench and choose connection method Standard TCP/IP over SSH
Enter in all the information and clicked Test Connection and get this popup message:
Information related to this connection:
Host: 127.0.0.1 Port: 3306 User: [username here] SSL: not enabled
A successful MySQL connection was made with the parameters defined for
this connection.
My team members were able to see all the database tables that they worked on under the schemas section, but my Schema section shows nothing. What am I missing and why can I not see the schemas despite getting a successful connection message?

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.

Connect to MySql db over SSH in Netbeans

In Netbeans, I need to create a connection to a remote MySql database over SSH. I am given SSH hostname, SSH username, SSH password, MySql hostname (127.0.0.1) and MySql username (root). In a new Connection Wizard I am not sure what to do since there is ssh involved. How should my JDBC Url look like? Is it even possible to achieve this from a gui wizard?
Hmm. I reckon the best way for you to do this is to set up port forwarding before attempting to connect to your remote database via NetBeans.
I'm not sure what OS your using but, assuming you are using some flavour of Linux here are the steps to take:
1) Forward a local port to your remote MySQL Database server
Open up a terminal window and type:
sudo ssh -L 6666:127.0.0.1:3306 <your_SSH_username<#<remoteserver.com>
You'll be prompted for your SSH password. Enter it.
2) In Netbeans go to Services and set up a new MySQL database connection with the following credentials:
host: 127.0.0.1
username: root (I'm assuming that the remote MySQL db allows remote root connections?)
password: password (I guess you must have a password for the MySQL database that you're connecting to?!)
The jdbc url should look something like this:
jdbc:mysql://127.0.0.1:6666?username=root&password=<your_remote_db_root_password>
There's a good post here for more details on port fowarding/tunnelling.
Good luck and I hope this helps!