Docker Container cant connect to MySQL database - mysql

I have a MySQL instance running in a docker container, available on my host system at port 3333. I already tested the connection via the MySQL workbench to verify, that the user I created is able to login to the SQL server.
I also have a wikijs (installation guide found here) instance running in a container.
I have provided all the required environment variables, including the information of the user I already tested, but the container always says that the connection was refused.
Does anybody have an idea on what the problem is?

No information does not help solving your problem but a wild guess:
By default docker containers are joining a virtual network separate from host named bridge.
You can't reach host by localhost or 127.0.0.1, because this is pointing to your docker container itself. To reach host directly either let container use hosts IP by --network=host (with some disadvantages) or use host.docker.internal as DNS-Name instead of an IP.
BUT you should not take the way over host, connect directly to the mySQL-container by using the alias or IP or the container. You'll get that by docker inspect <containername>. No need to map ports then..

Kindly try adjusting the port to 3306 and see if it works

Related

Can't connect to mysql database outside aws vm after creating succesfully

I followed this article to setup mysql server in my aws vm. At the time of creation of the vm itself I had allowed inbound traffic to port 3306 from all ip addresses.
After creating an admin account, I cannot access the account from outside the vm using sql workbench. I made changes in the property file to change the bind-address to 0.0.0.0 so that remote connections maybe allowed from outside. That also did not help.
What am I missing here? I did everything and still it won't connect. Appreciate any help on the matter.
AWS Security Groups
Based on the comments.
The issue was that mysql was setup to allow access from localhost. To solve the problem, external access needed to be allowed. This can be done by following the guide:
How To Allow Remote Access to MySQL

I am not able to connect to mysql server running on Google Compute engine from another instance using internal IP

I located the /etc/mysql/my.cnf file
I changed the bind-address
first to 0.0.0.0 I received a '111 Connection refused'
then I changed it to the instance I am trying to connect to It still says '111 Connection refused'
the firewall rule allows connection on port 3306 using internal ip so I dont know the problem. Thanks
It seems that you have already taken the necessary steps to connect to MySQL server from GCE your instance. Based on the Stackoverflow case here the recommendation to resolve this problem is to comment this line below (add # at the beginning of the line) in your my.cnf file:
skip-networking
Once done you need to restart MySQL service
sudo service mysql restart
On the GCP side, if you have allowed the IP ranges you want to use with the specified port(3306), it should work fine.
You can also use “nmap” command to verify if port 3306 is open on your GCE instance with MySQL installed.
GCP provides CloudSQL which is a managed MySQL instance. You can access CloudSQL from your GCE VM using private address. This feature reached beta recently. This link provides detailed information about using private IP to connect to your Cloud SQL instances.
Before configuring a Cloud SQL instance to use private IP, you need some steps to be taken. This document provides step by step instructions for configuring an instance to use private IP.
You can use 'netstat -tunlp | grep 3306' command to verify that the MYSQL process is running on port 3306.
This error can also occur when mysql user account does not accept connections from any IP addresses. It may still use localhost parameter to connect to the server. I would recommend adding a user with remote access or granting existing user access to remote sources. You can see this: link for the similar issue and follow the steps recommended there to resolve.

Connecting MySQL on EC2 to Tableau

I used a quick start guide to create a mysql database on EC2 that I can access and query using RStudio. However, I'd like to use Tableau Desktop to visualize the data as well. Tableau can connect to MySQL, but Im not sure how to make it work with EC2. I think I need to use port forwarding. I've Googled extensively and found a few examples but I'm completely new to this and don't know where to begin.
I'm using Terminal on Mac OSX. I'm able to login to SSH and to MySQL once in SSH.
Tableau needs a server, port, user, pass, and initial SQL statement. I'm assuming the initial SQL statement is just "use MyDatabase;"
I remember running into this issue awhile ago and found the solution again. I think the main thing to remember is that you have to use the localhost as the address in Tableau after you ssh into EC2 instead of the address of the actual EC2. You also have to setup your ssh to forward the port as you mentioned. Here is how you do that with PuTTY.
In the first screenshot you will see I added 127.0.0.1:3306 as the destination. This is the address of MySQL as setup on your server. I included 9990 as the source port. This is the port that PuTTY will be monitoring for any given calls. Once you have these defined click add and then save your session and connect with your server credentials through PuTTY. Go to Tableau.
In the second screenshot you will see that I used 127.0.0.1 for the server and 9990 for the port that I defined in PuTTY. You then add the credentials in Tableau that correspond to your MySQL user that is setup on EC2.

Connect Remotely to mysql running on a Amazon EC2 Instance

I'm trying to connect MySQL Workbench to an Amazon EC2 (Linux) instance that hosts a MySQL Database. (Not RDS but localhost). However for some reason, I can't get it to connect remotely.
Things Ive done:
- Set the security group to allow any IP to access port 3306
- Created a mysql user and granted all privledges on it.
- Modified the my.cnf to include bind-address=0.0.0.0 However i still cant connect.
On this instance I do have SSL cert installed and I am forwarded all http request to https?.. But im not sure if this has anything to do with it.
If anyone could guide my in the righ direction I would appreciate it.
I would personally give it an Elastic IP so it will have a public IP, then bind the mysql to that IP. Make sure the iptables are set to accept the mysql connections. I also wouldnt suggest leaving mysql open to every ip unless this is an absolute necessity.

How best to connect containers within Docker

Do i always need to use the --link command to link to containers to one another or can i just ping the ip of the 2nd container from the 1st container.
Example:
Container 1 running mysql (tcp 3306) : ip 10.0.0.7
Container 2 running lamp : ip 10.0.0.8
can 0.8 not just directly connect to 0.7 they are on the same bridge ?
Thanks once again for the help
Regards
Hareem Haque
It depends even on your network topology.
If you choose "secure" setup with --icc=false you will have to use --link for dockers to communicate.
Documentation at [1] explains it.
Link:
[1] - https://docs.docker.com/articles/networking/#communication-between-containers
Regards
Paolo
Basically, I added --icc=true to my docker opts and restarted docker. I just ran a test connecting a php container to a mysql container without using --link. Everything works great. I see no error. I can now easily connect containers together via bridge ip address.
If you want to connect containers on different hosts, the best option available right now is using Weave:
https://github.com/zettio/weave
Another is Open vSwitch, but it's too messy for my taste. Docker's acquisition of SocketPlane could result in something usable, but we are not there yet. I would go with Weave.