"Can't connect to local MySQL Server" using SSH tunnel - mysql

Starting an SSH tunnel to MySQL so MySQL Workbench can connect to the remote DB using the following command:
ssh -L 3306:localhost:3306 <username>#<domain> -N
MySQL Workbench is able to connect without issue doing this.
I was also trying to spin up a local copy of the Django application and connect to the remote test DB and I get met with:
django.db.utils.OperationalError: (2002, 'Can\'t connect to local MySQL server through socket \'/var/run/mysqld/mysqld.sock\' (2 "No such file or directory")'
Looking at the Django settings, everything looks correct. Just seems like Django is ignoring the tunnel despite using the same port. Django is in virtualenv so wonder if something there might be causing it.
Any suggestions?

I had to change the DB connection string in the settings.py to 127.0.0.1 instead of localhost.

Related

How to connect MYSQL Data Base to my Django app via an ssh

How to connect my Django app to MySQL DB via ssh. I have a MySQL DB hosted in Namecheap. I can connect to it via ssh using a terminal, is there any way I can do that??
You might be able to set up an SSH tunnel.
https://www.ssh.com/academy/ssh/tunneling/example

Connecting Jetbrains DataGrip to a remote database via SSH

I have an AWS Lightsail instance running the Bitnami configuration for Ubuntu 16.04.5 LTS and PHP7.
I can connect the the MySQL database using phpMyAdmin on the server via an SSH Tunnel. But when I try to configure DataGrip for SSH access to the database I receive the error message "Host '127.0.0.1' is not allowed to connect to this MySQL server".
When I remove "localhost" from the host field of the General tab then I receive the error "ExecutionException: SSH: Unable to find host/port in URL".
The following test and response appears to show a successful connection to the port:
cat < /dev/tcp/###.###.###.###/22
SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.6
I'm using keypair auth. Both the user name and the Private key file are the same used for the ssh tunnel when running phpMyAdmin.
Not sure what to try next. Any help appreciated.

MySQL: Unable to connect using TCP/IP over SSH

We have an EC2 and RDS instance on Amazon Web Services. I usually first connect to the server using Putty and then access the database through a tunnel from my localhost.
I am now trying to directly connect to the database using TCP/IP over SSH, but get the following error. I am able to connect other applications such as FileZilla directly without creating any tunnels, but not able to connect MySQL. Please advise. There is no entry in known_hosts file.
Error:
[Window Title]
MySQL Workbench
[Main Instruction]
Failed to Connect to MySQL at database.aws-server.rds.amazonaws.com:3306 through SSH tunnel at username#100.100.100.100:22 with user username
[Content]
Cannot open SSH Tunnel: Error connecting SSH tunnel: The host 100.100.100.100 fingerprints mismatch.
Expected key: hjd83iuwe98jdoiw8euoqeuo83eqe308
Server sent: 8ru84ru8ur984u8djc0938y4jddj398e
Please verify if it's correct.
To continue, delete entries for the host from the C:\Users\<USER>\AppData\Roaming\MySQL\Workbench\ssh\known_hosts file.
[OK]
I am connected to my rds database using the following script-
ssh -L 3406:database.aws-server.rds.amazonaws.com:3306 -i username#100.100.100.100
this command will create a tunnel on your local machine port 3406 of the mysql's default port 3306.
after that you can connect at 3406 port in your application
ssh-keygen -f "C:\Users<USER>\AppData\Roaming\MySQL\Workbench\ssh\known_hosts" -R "database.aws-server.rds.amazonaws.com"

openshift scaled app with port forward - Unable to access mysql on localhost

openshift scaled app with port forward - Unable to access mysql on localhost.
I have a simple php scaled app, I was able to setup the port forwarding for myapp. I can see that the 127.0.0.1:37731 is pointing to the openshift mysql gear.
But when I try to access mysql on command line or using mysql workbench, I am getting a
"Connected to MySQL at 127.0.0.1:37731 with user adminXXXXX", connection parameters are incorrect error.
I am ubuntu. "adminXXXXX:#127.0.0.1:37731:" is the connection string when I copy it from the workbench.
Try specifying the host separately.
E.g. after port forwarding, I entered
mysql --host=127.0.0.1:40793
and got
ERROR 2005 (HY000): Unknown MySQL server host '127.0.0.1:40793'
but this worked:
mysql --host=127.0.0.1 --port=40793

Django on EC2 using RDS

I have a Django App running on an EC2 instance and trying to connect to a RDS mysql Database instance.
I have created the RDS database and added a rule to the RDS Security group that allows for EC2 Security Group.
In my settings.py file, I have added the HOST to be the RDS EndPoint and the Port to be 3306 - along with the DB name, user and password.
I have installed libmysqlclient-dev, MySQL-python and mysql-client on the EC2 instance.
When I run ./manage.py syncdb, I get this error:
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")*
It looks like it is trying to connect to a local mysql server (which of course is not there, since I want it to connect to an RDS).
How can I get past this?
You don't set rds in default, or you loading wrong settings file. Python mysql trying to connect with localhost base, through socket (it's when HOST field is empty). You can try print DATABASE['default']['HOST'] in settings, or django shell to check host in settings.