As shown below, when I create a MySQL 8.0 Docker container and immediately try to connect to it with mysql -u root -ppass
, I get an error that there is no socket, but after waiting for a few minutes, I can reconnect and it succeeds. Is this because some initialization process was not completed and the first and second connection failed? If so, can I check the some kind of log to see if MySQL has finished the initialization process?
$ # WSL 2
$ docker -v
Docker version 20.10.12, build e91ed57
$ docker run -d --rm --name mysql_test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass mysql:8.0
$ docker exec -it mysql_test bash
# mysql -u root -ppass
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
# mysql -u root -ppass
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
# mysql -u root -ppass
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
...
By the way, the cause of the error is that there is no socket to connect to the MySQL server, so I tried to touch /var/run/mysqld/mysqld.sock
, but only got the following error, and I had to wait for several minutes to connect. mysql start
, mysql restart
also had no effect.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)