Installing MySQL in Docker fails with error message “Can't connect to local MySQL server through socket”

后端 未结 13 1453
轻奢々
轻奢々 2020-12-13 01:53

I\'m trying to install mysql inside a docker container,Tried various images from github, it seems they all manage to successfully install the mysql but when I try to run the

13条回答
  •  既然无缘
    2020-12-13 02:05

    My problem was that I was trying to connect from a version of mysql client that seems to be incompatible with the mysql server I installed (mysql:latest which installed version 8.0.22 at the time of this writing).

    my mysql client version:

    $ mysql --version
    mysql  Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using  EditLine wrapper
    

    The docker command that I used to install mysql:latest:

    $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=somerootpassword -e MYSQL_USER=someuser -e MYSQL_PASSWORD=someuserpassword -d -p 3306:3306 mysql:latest
    

    The errors I got when connecting from my local mysql client to the mysql server:

    $ mysql -u someuser -p -h 127.0.0.1
    ERROR 2026 (HY000): SSL connection error: unknown error number
    

    (sometimes I would get another error: "ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2". But I think this happens when I try to connect to the server too early after I started it)

    My solution was to install mysql:5.7 instead:

    $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=somerootpassword -e MYSQL_USER=someuser -e MYSQL_PASSWORD=someuserpassword -d -p 3306:3306 mysql:5.7
    

    and then I can connect to the server (after waiting perhaps 1 minute until the server is ready to accept connections):

    $ mysql -u someuser -p -h 127.0.0.1
    

提交回复
热议问题