忘備録。
古い Django で作られたシステムがあって、訳あってローカルで動かしたい。
docker-compose があったので、動かした際にハマった問題。
version: '3.3' services: db: image: 'mysql:5.7.22' restart: always ports: - '3306:3306' environment: MYSQL_DATABASE: root MYSQL_USER: foo MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
docker-compose up してビルドして MySQL を起動する
次にローカルから MySQL につなぎ適当にユーザーと権限を付与。
めんどかったので全て解放した。
$ mysql -u root -h 127.0.0.1 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 96 Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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>
Django の設定ファイルの DB のホストを `127.0.0.1` にする。
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'HOST': '127.0.0.1', 'NAME': 'DBNAME', 'USER': 'USERNAME', 'PASSWORD': '', }, }
あとは syncdb して migrate して runserver したらいけた。
ハマったポイントが、 HOST 名。最初 Docker 内のホスト名にしたが、127.0.0.1 で良いみたい。