Docker Community Forums

Share and learn in the Docker community.

Not able to connect MYSQL from docker. please help ASAP

Hello Peers ,

I have downloaded MYSQL docker image . Now trying to connect to MYSQL using host given in the IPaddress section of Docker inspect (say “172.17.0.2” ), port 3306 , username :root , and database : mysql.

I am trying to run an R script , where in I have placed the following Database connection ::
con <- dbConnect(RMySQL::MySQL(), dbname = “mysql”, host=“172.17.0.2”, port=3306,
username = “root”, password = )

But getting error , stating the host does not exist.

I even tried using various options of host like “localhost”. But still failing to connect stating ,
Error in .local(drv, …) :
Failed to connect to database: Error: Can’t connect to MySQL server on ‘172.17.0.2’ (0)
Calls: dbConnect -> dbConnect -> .local -> .Call

Please help on this , ASAP.

Thanks
Asmita

Please view this suggestion

Please give us more information: What system are you using (Linux, Windows…), how do you start the MySQL container, where is the R script running (on the host or in a container)?
In general, you shouldn’t have to inspect a container. The IP you see there is an internal address that you don’t need to access the database.

Hello@tekki ,

I have installed docker quickstart terminal on Oracle Virtual Box (VM).
R script is placed in a local directory in my windows desktop.

I am logging in thru docker quickstart terminal , and going to the path in which the R script is placed , in my local desktop , through the quick start terminal using cd

then I am running the rscript (say test.R) by using

Rscript test.R

Please note , the test.R has the db connectivity to mysql as follows :------

Connect to docker database

con <- dbConnect(RMySQL::MySQL(), dbname = “”, host=“127.0.0.1”, port=3307,
username = “root”, password = “pwd”)

also , mysql container has been created aftre pulling the latest mysql image from docker hub
aftre doing cd to the path , where the r script is placed , whenever I am tryin to run using

Rscript test.R , that time ,it s showing the error of not connecting to the host.

Are you sure your MySQL is on port 3307?

If you are on Windows Home and use Docker Toolbox, read ‘Get started with Docker Machine and a local VM’.

Hello @tekki , i have tried with other ports , 3306 , 33060 as well.

I have downloaded the mysql image , and not using mysql local server

You still didn’t tell us how you start the MySQL container. Do you publish port 3306? Check with docker container ls.