I installed docker, got the most popular box with proxySQL.
docker run -d -p 6032:6032 --name proxysql prima/proxysql:latest
then I tried to connect to it from my local mysql like so:
mysql -u admin -padmin -h 127.0.0.1 -P6032
and I'm getting this error:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"
I tried this trick with twindb/proxysql:latest and prima/proxysql:latest docker images and the result was the same :(
You cannot connect to proxysql from outside the container in default config. bash into the proxysql container and then execute
mysql -u admin -p<password-here> -h 127.0.0.1 -P 6032 --prompt='proxysql>'
default password will be the admin
You need to map 6033 instead of 6032
docker run -d 6033:6033 --name proxysql prima/proxysql:latest
And then run below
mysql -u admin -padmin -h 127.0.0.1 -P6033
Inside the container mysql listens on 127.0.0.1:6032 and for outside connections it listens on 0.0.0.0:6033. So you need to use 6033 for connections from outside the container
Related
I try connect my mysql host DB from docker container by using host mode and I get the error:
docker run --rm -it --network=host mysql mysql -h 127.0.0.1 -utestuser -p
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
The base of my work is stackoverflow-answer https://stackoverflow.com/a/24326540/1514029
My host mysql version is 8.0.25.
I tried in my.cnf bind-address = 0.0.0.0 and bind-address = 172.17.42.1
Every binding have the same problem.
I grant the testuser user access to 127.0.0.1 by statements
CREATE USER testuser#127.0.0.1 IDENTIFIED BY 'blah'
grant all privileges on *.* to testuser#127.0.0.1 with grant option
On docker bridge mode my connection work fine only on docker host mode it fails!
It must be a network problem!?
you can use:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.25
I created a test_mysql using the following command:
docker run -d -p 3306:3306 --name=test_mysql --env="MYSQL_ROOT_PASSWORD=123" mysql
I got the IP address using docker inspect test_mysql. The IP is 172.17.0.2.
The strange thing is that when I tried to connect to mysql server on my local using
mysql -uroot -p123 -h 172.17.0.2 -P 3306
An error raised:
ERROR 2003 (HY000): Can't connect to MySQL server on '172.17.0.2' (51)
However, if I use the localhost IP address instead it did work:
mysql -uroot -p123 -h 127.0.0.1 -P 3306
My question is why I can't connect to the container use docker inspect result while localhost IP works?
1) while localhost IP works?
Let's see again your command to start container:
docker run -d -p 3306:3306 --name=test_mysql --env="MYSQL_ROOT_PASSWORD=123" mysql
The -p 3306:3306 will "bind" the port 3306 of host to the port 3306 of the container. As a result, we can see that if there is any connections come to port 3306, they will be forwarded to the port of the container.
So, your connections on local IP will work:
mysql -uroot -p123 -h 127.0.0.1 -P 3306
See more detail on Docker page
2) why I can't connect to the container use docker inspect result
It seems your container is connected to the default bridge network(docker0 may have IP:172.17.0.1 in your case ) which is often created by default when you install Docker.
You can find more detail in Docker network page.Therefore, inside your container, you may "see" the bridge (you can try to use ping command", but from your local host, it may not know how to find/resolve the 172.17.0.2 and you got that error.
I want to change the default exposed port for mysql docker container, but if i try to use this command:
docker run --detach --name=test-mysql -p 52000:52000 --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
It does not work. mysql -uroot -pmypassword -h 127.0.0.1 -P 52000
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
If I use the standard port 3306:3306 then it works fine, but i want change the port. Is it possibile?
I had already tried -p 52000:3600 , but i have always gotten:
mysql -uroot -pmypassword -h 127.0.0.1 -P 52000
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
You need to map the container-port 3306 on the prefered TCP port (of your server):
-p <host_port>:<container_port> (map container_port xx on host_port yy)
So for your mysql
docker run --detach --name=test-mysql -p 52000:3306 --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
there is also a second option:
don't map a port to another port but let mysql itself run directly on another port using the MYSQL_TCP_PORT-variable.
example:
docker run --detach --name=test-mysql --env="MYSQL_TCP_PORT=52000" mysql
is there any way to connect remote docker container mysql server?
I am installing magento web application, now I have a situation like I need to use/point the existing remote docker container database. I have make port forwarding in order to access database from remote machine but it doe not work.
docker run -it -d -p 3002:80 -h tm.gworks.mobi -v /var/www/public --privileged --name database magedev
For testing purpose in remote machine I have tried like mysql -u root -h 192.168.1.21:3002 -p in mysql console but it does not connect, it throws error ERROR 2005 (HY000): Unknown MySQL server host '192.168.1.21:3002' (-2)
Docker run command should be,
docker run -it -d -p 3002:3306 -h tm.gworks.mobi -v /var/www/public --privileged --name database magedev
default mysql port is 3306 but I listen port 80 which is my nginx port so it can't be to allow.
mysql -u root -h 192.168.1.21 -P 3002 -p
now everything works fine
I created my container like this:
$ docker run -d -p 33060:3306 myimage
Then I try connect from host to mysql server in container:
$ mysql -uroot -proot -P 33060
I got this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
It odd because in Navicat only I changed the port and work fine:
But If I have the IP of the container:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' mycontainer
172.17.0.55
Then I can connect to mysql server successfully:
$ mysql -uroot -proot -h 172.17.0.55
But it is a tedious task have to check the ip each time I create a new container to connect to mysql. There any settings I can do to make this task simpler?
This is not a Docker issue. By default the mysql command-line client will connect to a local (Unix) socket instead of a network one, even if you specify -P.
This behavior is described in the documentation:
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given
You have to pass the -hlocalhost option, or you can set your connection defaults in /etc/mysql/my.cnf