【问题标题】:Django Connect remote Mysql OperationalError 2026Django Connect 远程 Mysql OperationalError 2026
【发布时间】:2019-11-23 03:40:59
【问题描述】:

我已经使用 Django + mysql 好几天了。今天早上我突然发现我无法连接远程mysql。

% python manage.py makemigrations

它提高了

django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed')

也当

python manage.py runserver

这是我的环境:

macOS 10.15 + Django 2.2.6 + MySQL 5.7(在远程服务器上,ubuntu 18.04)+ python 3.6.8(使用 conda env)

我已经寻找了一些解决方案,例如:

  • 降级openssl

    软件包 openssl 冲突: openssl=1.0.2r python=3.6.8 -> openssl[version='>=1.1.1a,

  • 在我的 .conf 文件中添加 use_pure=True

    什么都没变

  • 在我的 .conf 文件中添加 skip_ssl

    什么都没变

注意

  • 在服务器(我部署我的站点,ubuntu 18.04)上,我的站点使用 gunicorn + Nginx 运行良好
  • 直到今天,所有事情都运行良好。
  • 当我发现这个问题时,网站崩溃了,但当我重新启动它时,它运行良好。
  • 我猜可能是服务器上的某些更新(自动升级)导致了问题,但还没有找到。

我的一些代码

# setting.py


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'read_default_file': mysqlPath,
            'init_command': 'SET default_storage_engine=INNODB',
        },
    }
}

# my_remote.cnf (which define the 'mysqlPath' in setting.py)

[client]
database = mydatabase
user = myusername
password = mypassword   
default-character-set = utf8
host = myremotehost
port = 3306
use_pure = True
skip-ssl
skip_ssl
skip-ssl = True
skip_ssl = True

【问题讨论】:

  • 问题通过在mysql conf中添加skip_ssl并重启解决;但仍然想知道为什么以及这种方法会导致一些问题吗?

标签: python mysql django ssl operationalerror


【解决方案1】:

这是因为您的服务器尚未设置 SSL。因此,错误是在服务器端引起的。

正如已经提到并成功尝试过的那样,解决方案是让服务器准备好 SSL 或在开发过程中将 skip_ssl 设置为 true

https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html

【讨论】:

    猜你喜欢
    • 2013-05-04
    • 1970-01-01
    • 2011-12-11
    • 2019-11-03
    • 2018-11-30
    • 2021-12-16
    • 1970-01-01
    • 2012-03-31
    • 2012-12-19
    相关资源
    最近更新 更多