python mysql ssl,将MySQL连接器与Python一起使用时SSL连接错误

I'm using Python 3.6 (but I get the same error with Python 2.7) and mysql-connector-python in an Anaconda's environment to code a simple script to access my database hosted in Hostgator. This is the error:

Traceback (most recent call last):

File "/home/usuario/anaconda3/envs/fakebook/lib/python3.6/site-packages/mysql/connector/connection_cext.py", line 176, in _open_connection

self._cmysql.connect(**cnx_kwargs)

_mysql_connector.MySQLInterfaceError: SSL connection error: SSL_CTX_set_tmp_dh failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "teste.py", line 6, in

passwd="senha"

File "/home/usuario/anaconda3/envs/fakebook/lib/python3.6/site-packages/mysql/connector/__init__.py", line 172, in connect

return CMySQLConnection(*args, **kwargs)

File "/home/usuario/anaconda3/envs/fakebook/lib/python3.6/site-packages/mysql/connector/connection_cext.py", line 78, in __init__

self.connect(**kwargs)

File "/home/usuario/anaconda3/envs/fakebook/lib/python3.6/site-packages/mysql/connector/abstracts.py", line 731, in connect

self._open_connection()

File "/home/usuario/anaconda3/envs/fakebook/lib/python3.6/site-packages/mysql/connector/connection_cext.py", line 179, in _open_connection

sqlstate=exc.sqlstate)

mysql.connector.errors.InterfaceError: 2026 (HY000): SSL connection error: SSL_CTX_set_tmp_dh failed

My code is very simple, it just try to connect to the database:

import mysql.connector

mydb = mysql.connector.connect(

host="192.xxx.xxx.xx",

user="root",

passwd="senha"

)

print(mydb)

I've used this library several times on other computers, I've also connected to this same database through my computer, using the same library and it always worked with this code. I tried with MySQL Workbench and seems it is connecting to the database using the same credentials that are in my code. I've already tried to ask help to the server support, my IP is allowed to access the database and even so I can't connect with Python. I tried to reinstall the library, but nothing changed.

Thank you everyone!

解决方案

This worked for me (Ubuntu 16.04 LTS). From terminal:

re-create certificates (datadir is of your choice):

mysql_ssl_rsa_setup --datadir=/data/dir/

Add the following to /etc/mysql/mysql.conf.d/mysqld.cnf:

ssl-ca=/data/dir/cacert.pem

ssl-cert=/data/dir/server-cert.pem

ssl-key=/data/dir/server-key.pem

Restart mysql server: sudo service mysql restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值