LoginSignup
0
0

More than 3 years have passed since last update.

文系出身エンジニアが学ぶDockerのDBサーバにクライアントツールからログインできない時の対処法

Last updated at Posted at 2020-02-29

環境

OS :macOS Catalina version: 10.15.13
MySql: version: 5.7.26
クライアントツール: Sequel Pro

事象

クライアントツールでDockerコンテナにあるDBサーバーにアクセスできない。
image.png

原因

docker-compose.ymlでDBサーバのポートを指定をしていなかったため。

docker-compose.yml
db:
  image: mysql:5.7
  volumes:
    - db-volume:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD: password

解決策

ポートを追加する。
ホストのOS(自分のPC)から繋ぐ時はポートが必要。

docker-compose.yml
db:
  image: mysql:5.7
  # 下記のようにポートを指定
  ports:
    - 3306:3306
  volumes:
    - db-volume:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD: password

image.png

ちなみに、、、

下記コマンドでDockerコンテナに入り、

$ docker-compose exec db bash

mysqlコマンドでログインすると、ポート番号なしでもログインできます

root@******:/# mysql -u root -h 127.0.0.1 -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

また、MySQLのver8以降の場合SequelProで接続出来ないようです。
私は今回version: 5.7だったのであまり詳しくは触れませんが、その場合は下記を参考にしたら良いかもしれません
Sequel Proで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