为什么 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:Python38libsite-packagesmysqlconnectorconnection.py", line 819, in reset_session
self.cmd_reset_connection()
File "C:Python38libsite-packagesmysqlconnectorconnection.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 连接器/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 Connector/Python(在 do_handshake() 中修复 server_version),也可以尝试 MariaDB Connector/Python.它目前处于测试阶段,但预计本月仍会 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
)
相关文章