0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Docker】【MySQL】ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)解消法

Posted at

状況

docker compose run db bashを実行したところ以下のようにエラーが発生しました。

ターミナル
$ docker compose run db bash
docker compose run db bash
bash-4.4$  mysql -u root -p
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)

解消法

以下の手順で実行することで解消できました。

ターミナル
$ docker compose up -d
[+] Running 3/3
 ⠿ Container rails-gitlint-test2-db-1   Healthy                                                       4.6s
 ⠿ Container rails-gitlint-test2-api-1  Started                                                       5.1s
 ⠿ Container rails-gitlint-test2-web-1  Started                                                       5.4s

$ docker compose exec db bash
bash-4.4$ mysql -u root -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?