DjangoのDBの接続先をさくらインターネットのphpMyAdminに繋げる方法がわかりません・
▪️ 端末
Mac
▪️ 使用ドライバ
pymysql, mysqlclient ※ 両方試しました
▪️ 試したこと
現状試したことは、以下の通りです。
- mysqlのlocalhost接続 → 成功
- Sequel Proを用いた接続 → 成功
- さくらインターネットのphpMyadmineへの接続 → 失敗
▪️ setting.pyのデータベース接続文字列
python
1DATABASES = { 2 'default': { 3 'ENGINE': 'django.db.backends.mysql', 4 'NAME': 'データベース名', # phpMyAdminで作成したデータベース名を記載しています 5 'USER': 'ユーザ名', # [xxx.sakura.ne.jp]の[xxx]部分を記載しています 6 'PASSWORD': 'xxxxxxx', 7 'HOST': 'xxxxxx.xx.sakura.ne.jp', 8 'PORT': '' # ここは空にしています 9 } 10}
▪️ manage.py
manage.pyの行頭に以下2行を加えています
python
1import pymysql 2pymysql.install_as_MySQLdb()
▪️ エラー詳細
$ python manage.py migrate execute_from_command_line(sys.argv) File "/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 350, in execute self.check() File "/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 379, in check include_deployment_checks=include_deployment_checks, File "/anaconda3/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 59, in _run_checks issues = run_checks(tags=[Tags.database]) File "/anaconda3/lib/python3.7/site-packages/django/core/checks/registry.py", line 71, in run_checks new_errors = check(app_configs=app_configs) File "/anaconda3/lib/python3.7/site-packages/django/core/checks/database.py", line 10, in check_database_backends issues.extend(conn.validation.check(**kwargs)) File "/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/validation.py", line 9, in check issues.extend(self._check_sql_mode(**kwargs)) File "/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode with self.connection.cursor() as cursor: File "/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 255, in cursor return self._cursor() File "/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 232, in _cursor self.ensure_connection() File "/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection self.connect() File "/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection self.connect() File "/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 194, in connect self.connection = self.get_new_connection(conn_params) File "/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection return Database.connect(**conn_params) File "/anaconda3/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect return Connection(*args, **kwargs) File "/anaconda3/lib/python3.7/site-packages/pymysql/connections.py", line 325, in __init__ self.connect() File "/anaconda3/lib/python3.7/site-packages/pymysql/connections.py", line 630, in connect raise exc django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'xxxxxx.xx.sakura.ne.jp' (timed out)")
▪️ 最後に
個人的にはSSHの設定をsetting.pyのデータベース設定に付け加えないといけないのではないかと考えているのですが、
記載方法がわかりません。
お手数をおかけしますが、どうかご教授のほどお願いいたします。
回答1件
あなたの回答
tips
プレビュー