How to connect to Docker MySQL databse from a different virtual machine - mysql

I have two EC2 instances.
vm1 - has mysql server running as a Docker container
vm2 - has mysql client installed.
Now I want to connect from vm2 to the mysql container running in vm1. In vm1, the container is exposed 3306 to the container port 3306
I tried first telnetting the port as:
telnet <ip-of-vm1> 3306
and I get the below error:
Trying 10.128.15.6...
telnet: Unable to connect to remote host: Connection refused
I even allowed the firewall rules to allow all inboud. And mysql container running without any errors.
Can someone help me on this?

Related

Cannot access MySQL container in VPS from MySQL Workbench In My PC

I've created a docker container that runs MySQL on it and exposes it on the default port (3306) on a DO droplet (Ubuntu 20).
I tried accessing it on my laptop with the following parameters:
Hostname: (VPS's IP address. I also tried Public Gateway IP)
Connection: Standard (TCP/IP)
Port: 3306
Username: root
Password: (Password I have set while creating the container)
The error message just says "Could not connect to localhost"
Am I missing a step that maybe exposes the container to the internet?
After a couple of hours, I found out that the docker run command has to have -p parameter. -p=3306:3306 in my case.

How to connect to MySQL database in docker container from Vagrant box?

I have a Symfony project which I'm running in 3 docker containers:
A PHP-FPM container
A NginX container
A MySQL container
I have another (Laravel) project which is running through the pre-packaged Vagrant Box setup (Homestead).
I'm now trying to connect to the MySQL database (of the Docker setup) from within the Vagrant box of my Laravel project.
What I know for sure:
I can connect to my MySQL database from my host machine through Sequel Pro.
Host: 127.0.0.1
Port: 3306
What I don't know:
Which host / port should I define in my Laravel project in order to successfully connect to the MySQL database from my docker container setup?
If you can connect from your Workstation in should also work from the VM.
Simply use as connection parameter:
IP: Your Workstation IP
Port: 3306
Important: Publish the port of the Container with : -p 3306:3306

Connecting SQL running on Vagrant machine through remote host?

I am trying to connect Emma to MySQL running on Vagrant Machine with nginx from a remote location. The server (host) has a static ip that can be accessed through internet. It also has its own running MySQL instance that I can connect to. However I want to connect to Vagrant's MySQL from a remote location.
You will need to expose the port of the MySQL server's running on Vagrant to the public internet. There are a number of ways, but the simplest should be configuring Vagrant with port forwarding.
Since you already have another MySQL server running on the host, you would need to forward on another (free) port than the default, for example 6306:
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 3306, host: 6306
end
You would also need to explicitly specify that port in the connection url in Emma.

Remote Access MySQL connection error

I am trying to remotely connect to a MySQL server. I have followed advice from (1) and setup a user on the ip address I will be remotely accessing from.
user$ mysql -u TestUser -p -h 129.169.66.149
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '129.169.66.149' (60)
I have checked and the port (default, 3306) is correct and the ip address is correct. MySQL is also running.
From a remote computer, I can successfully ping the server
ping 129.169.66.149
64 bytes from 129.169.66.149: icmp_seq=48 ttl=63 time=1.010 ms
But when I use Telnet:
TELNET 129.169.66.149
Trying 129.169.66.149...
telnet: connect to address 129.169.66.149: Operation timed out
telnet: Unable to connect to remote host
Can anyone advise? Is this a firewall issue?
(1) - https://superuser.com/questions/826896/access-wordpress-mysql-database-remotely
First try to check TCP connection issue, using netcat and telnet : on the mysql server, stop mysqld (to release port 3306) and run netcat on listen mode :
nc -l -p 3306
Now, netcat is listening port 3306 (like mysqld does when it's running) and will show what happen on that port (incoming connections, what's in the wire...).
On your remote computer (mysql client), try to connect to the mysql server host :
telnet 129.169.66.149 3306
or :
nc 129.169.66.149 3306
If this is not working, this is not a mysql server configuration issue but a network issue, and you must check your router firewall rules.
Otherwise, your problem comes from mysql server settings. Check your mysql configuration file for bind-address, and remove them to make mysqld accept clients from any IP address.
The 3306 port on the 129.169.66.149 server is closed you'll have to open this port
Use this reference as a guide http://www.cyberciti.biz/faq/linux-unix-open-ports/

MySQL RDS Database Connection

I just created a test RDS instance through the AWS console, and it has been created successfully (it says it is running and available). I currently have my security groups configured to SSH port 22 (MyIP) Custom TCP Rule port 3307 (myIP) and HTTPS port 443 (MyIP). I am currently trying to connect through MySQL workbench. I am using the endpoint of "RDS_URL" :3307 and inputting my username and password. Every time I try to connect, I get this error:
Can't connect to MySQL server "-RDS_URL-" (10060)
Any suggestions?
Default MySQL port is 3306, In RDS you can't change it but in datacenter hosted DB, you can change by changing in my.cnf file and restart it. Before doing it open the port from firewall rules.