无法连接docker里的mysql服务器
PHP中文网
PHP中文网 2017-04-17 15:02:32
0
1
836

1.宿主机无法连接docker里的mysql
报错如下:
[root@localhost ~]# mysql -h 127.0.0.1 -uroot -p -A
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

如果是localhost。则报错如下:
[root@localhost ~]# mysql -P 3306 -uroot -p -A
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
Ty80

First of all, you need to figure out what your port 3306 is listening to?
If you have not started mysql on the host machine on 3306, you can use it when starting the mysql program in docker

docker start  -p 3306:3306 。。。。

Map docker’s 3306 port to the host’s 3306 port.
This way you can use it on the host machine

mysql -h localhost -uroot -p 

Connect to mysql in docker.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!