为什么mysql.connector可以在python2.7而不是python3上正常工作? [英] Why mysql.connector works without problem with python2.7 and not with python3?

查看:199
本文介绍了为什么mysql.connector可以在python2.7而不是python3上正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了其他帖子,例如: 在那里一种在MariaDB 10.4.7中使用mysql-connector-python中的'pool_reset_connection'的方法?

I checked different post like: Is there a way to use 'pool_reset_connection' from mysql-connector-python with MariaDB 10.4.7?

但是我无法解决问题,我有一个用python 2.7编写的程序;现在我将所有内容移至python 3,但是mysql.connector出现问题.

But I can't solve my isue, I have a program write in python 2.7; now I'm moving everything to python 3 but I got problems with mysql.connector.

此刻,我正在使用python 3.8.2和mysql-connector-python == 8.0.19,但是我尝试使用不同版本的python 3,但是当我尝试使用mysql.connector时,我总是遇到相同的错误关闭连接.

In this moment I'm using python 3.8.2 and mysql-connector-python==8.0.19 but I try with different version of python 3, but I was getting always the same error on mysql.connector when I try to close the connection.

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\mysql\connector\connection.py", line 819, in reset_session
    self.cmd_reset_connection()
  File "C:\Python38\lib\site-packages\mysql\connector\connection.py", line 1166, in cmd_reset_connection
    raise errors.NotSupportedError("MySQL version 5.7.2 and "
mysql.connector.errors.NotSupportedError: MySQL version 5.7.2 and earlier does not support COM_RESET_CONNECTION.

...
...

mysql.connector.errors.OperationalError: 1047 (08S01): Unknown command

我不确定如何解决它,我尝试以不同的方式增加池并使用不同的池,或者只是关闭连接,但是在一个大型项目中,当池耗尽后,我确实需要关闭连接,但是无法解决这个问题;有人可以帮我吗?

I'm not sure how to solve it, I try in different way increasing the pool and having different pool or just shutdown the connection but in a big project after I got pool exhaust so I really need close the connection but I can't solve this issue; can someone help me pls?

我什至尝试按照另一个stackoverflow票证中的说明更改mysql-connector库,但是每次更改它时,我都会遇到其他问题.

I try even to change the mysql-connector library as explained in the other stackoverflow ticket but every time I change it I got other problems.

推荐答案

MySQL Connector/Python如何检测服务器版本是一个问题:

It's a problem how MySQL Connector/Python detects the server version:

由于复制不适用于2位主版本号,因此MariaDB使用所谓的RPL hack,该版本是10.0版引入的,并将以下版本号发送给客户端5.5.5-10.4.13-MariaDB.另请参见 MariaDB的第一部分是什么版本字符串的意思是.

Since replication doesn't work with a 2-digit major version number, MariaDB uses a so called RPL hack which was introduced with version 10.0 and sends the following version number to the client 5.5.5-10.4.13-MariaDB. See also What does the first part of the MariaDB version string mean.

由于MariaDB Connector/Python无法识别它,因此假定服务器版本号为5.5.5,并且在检查> = 5.7.3时将引发NotSupportedError异常.

Since MariaDB Connector/Python is not aware of it, it assumes that the server version number is 5.5.5 and will raise a NotSupportedError exception when checking >= 5.7.3.

您可以修补MySQL连接器/Python(在do_handshake()中修复server_version),也可以尝试使用MariaDB连接器/Python.目前是beta版,但预计GA仍会在本月(pip3 install mariadb)

You can either patch MySQL Connector/Python (fixing server_version in do_handshake()) or you can try MariaDB Connector/Python. It's currently beta, but GA is expected still this month (pip3 install mariadb)

这篇关于为什么mysql.connector可以在python2.7而不是python3上正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆