{"id":27583,"date":"2024-11-24T13:37:39","date_gmt":"2024-11-24T05:37:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27583\/"},"modified":"2024-11-24T13:37:39","modified_gmt":"2024-11-24T05:37:39","slug":"pycharm-%e4%b8%ad%e8%bf%90%e8%a1%8c-django-%e8%bf%81%e7%a7%bb%e8%84%9a%e6%9c%ac%e6%97%b6%e5%87%ba%e7%8e%b0-mysql-%e8%bf%9e%e6%8e%a5%e9%94%99%e8%af%af%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27583\/","title":{"rendered":"PyCharm \u4e2d\u8fd0\u884c Django \u8fc1\u79fb\u811a\u672c\u65f6\u51fa\u73b0 MySQL \u8fde\u63a5\u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173129334821748.jpg\" class=\"aligncenter\" title=\"PyCharm \u4e2d\u8fd0\u884c Django \u8fc1\u79fb\u811a\u672c\u65f6\u51fa\u73b0 MySQL \u8fde\u63a5\u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"PyCharm \u4e2d\u8fd0\u884c Django \u8fc1\u79fb\u811a\u672c\u65f6\u51fa\u73b0 MySQL \u8fde\u63a5\u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u4e2d\u8fd0\u884c\u8fc1\u79fb\u811a\u672c\u65f6\u51fa\u73b0\u8fde\u63a5\u9519\u8bef<\/strong><\/p>\n<p>\u5728pycharm\u4e2d\u4f7f\u7528django\u65f6\uff0c\u8fd0\u884c\u8fc1\u79fb\u811a\u672c\u201c manage.py migrate\u201d\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u201cdjango.db.utils.operationalerror\u201d\u3002\u672c\u6587\u65e8\u5728\u89e3\u7b54\u8fd9\u4e00\u95ee\u9898\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n<p>\u4f7f\u75283.7.4\u7248python\u30013.2.19\u7248django\u548c1.4.6\u7248mysqlclient\u65f6\uff0c\u8fd0\u884c\u201cpython manage.py makemigrations\u201d\u6210\u529f\uff0c\u4f46\u8fd0\u884c\u201cpython manage.py migrate\u201d\u65f6\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>mysqldb._exceptions.operationalerror: (2026, 'ssl connection error: unknown error number')<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u539f\u56e0\u5206\u6790<\/strong><\/p>\n<p>\u8be5\u9519\u8bef\u5f80\u5f80\u662f\u7531\u4e8e\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7684ssl\u914d\u7f6e\u4e0d\u5339\u914d\u5f15\u8d77\u7684\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li><strong>\u5728mysql\u670d\u52a1\u5668\u914d\u7f6e\u4e2d\u7981\u7528ssl<\/strong><\/li>\n<\/ol>\n<p>\u5728mysql\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\u7684[mysqld]\u90e8\u5206\u4e0b\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>skip_ssl<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u91cd\u542fmysql\u670d\u52a1\u5668\u3002<\/p>\n<ol>\n<li><strong>\u9a8c\u8bc1\u5ba2\u6237\u7aefssl\u652f\u6301<\/strong><\/li>\n<\/ol>\n<p>\u786e\u4fdd\u6240\u4f7f\u7528\u7684mysqlclient\u652f\u6301\u5b89\u5168\u8fde\u63a5\u3002\u5982\u679c\u652f\u6301\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u914d\u7f6e\uff1a<\/p>\n<pre>DATABASES = {\n    'default': {\n        ...\n        'OPTIONS': {\n            'ssl': {\n                'ca': '\/path\/to\/ca.pem',\n                'cert': '\/path\/to\/client-cert.pem',\n                'key': '\/path\/to\/client-key.pem',\n            },\n        },\n        ...\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u8def\u5f84\u5e94\u6307\u5411\u76f8\u5e94\u7684\u8bc1\u4e66\u548c\u5bc6\u94a5\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5176\u4ed6\u6b65\u9aa4<\/strong><\/p>\n<p>\u5982\u679c\u4e0a\u8ff0\u89e3\u51b3\u65b9\u6848\u4e0d\u8d77\u4f5c\u7528\uff0c\u8fd8\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684\u6570\u636e\u5e93\u914d\u7f6e\u3002<\/li>\n<li>\u68c0\u67e5mysql\u670d\u52a1\u5668\u662f\u5426\u6b63\u5728\u8fd0\u884c\u4e14\u53ef\u4ee5\u8bbf\u95ee\u3002<\/li>\n<li>\u786e\u4fddmysql\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4f7f\u7528\u76f8\u540c\u7248\u672c\u7684tls\/ssl\u5e93\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fPyCharm \u4e2d\u8fd0\u884c Django \u8fc1\u79fb\u811a\u672c\u65f6\u51fa\u73b0 MySQL \u8fde\u63a5\u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e2d\u8fd0\u884c\u8fc1\u79fb\u811a\u672c\u65f6\u51fa\u73b0\u8fde\u63a5\u9519\u8bef \u5728pycharm\u4e2d\u4f7f\u7528django\u65f6\uff0c\u8fd0\u884c\u8fc1\u79fb\u811a\u672c\u201c manage.py migrate\u201d\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u201cdjango.db.utils.operationalerror\u201d\u3002\u672c\u6587\u65e8\u5728\u89e3\u7b54\u8fd9\u4e00\u95ee\u9898\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u89e3\u51b3\u6b64\u95ee\u9898\u3002 \u95ee\u9898\u63cf\u8ff0 \u4f7f\u75283.7.4\u7248python\u30013.2.19\u7248django\u548c1.4.6\u7248mysqlclient\u65f6\uff0c\u8fd0\u884c\u201cpython manage.py makemigrations\u201d\u6210\u529f\uff0c\u4f46\u8fd0\u884c\u201cpython manage.py migrate\u201d\u65f6\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a mysqldb._exceptions.operationalerror: (2026, &#8216;ssl connection error: unknown error number&#8217;) \u767b\u5f55\u540e\u590d\u5236 \u539f\u56e0\u5206\u6790 \u8be5\u9519\u8bef\u5f80\u5f80\u662f\u7531\u4e8e\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7684ssl\u914d\u7f6e\u4e0d\u5339\u914d\u5f15\u8d77\u7684\u3002 \u89e3\u51b3\u65b9\u6848 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a \u5728mysql\u670d\u52a1\u5668\u914d\u7f6e\u4e2d\u7981\u7528ssl \u5728mysql\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\u7684[mysqld]\u90e8\u5206\u4e0b\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a skip_ssl \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\u91cd\u542fmysql\u670d\u52a1\u5668\u3002 \u9a8c\u8bc1\u5ba2\u6237\u7aefssl\u652f\u6301 \u786e\u4fdd\u6240\u4f7f\u7528\u7684mysqlclient\u652f\u6301\u5b89\u5168\u8fde\u63a5\u3002\u5982\u679c\u652f\u6301\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u914d\u7f6e\uff1a DATABASES = { &#8216;default&#8217;: { &#8230; &#8216;OPTIONS&#8217;: { &#8216;ssl&#8217;: { &#8216;ca&#8217;: &#8216;\/path\/to\/ca.pem&#8217;, &#8216;cert&#8217;: &#8216;\/path\/to\/client-cert.pem&#8217;, &#8216;key&#8217;: &#8216;\/path\/to\/client-key.pem&#8217;, }, }, &#8230; } } \u767b\u5f55\u540e\u590d\u5236 \u8bf7\u6ce8\u610f\uff0c\u8def\u5f84\u5e94\u6307\u5411\u76f8\u5e94\u7684\u8bc1\u4e66\u548c\u5bc6\u94a5\u6587\u4ef6\u3002 \u5176\u4ed6\u6b65\u9aa4 \u5982\u679c\u4e0a\u8ff0\u89e3\u51b3\u65b9\u6848\u4e0d\u8d77\u4f5c\u7528\uff0c\u8fd8\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u6b65\u9aa4\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27583","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27583"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27583\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}