Why mysql.connector works without problem with python2.7 and not with python3?(为什么 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)
这篇关于为什么 mysql.connector 在 python2.7 和 python3 上没有问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 mysql.connector 在 python2.7 和 python3 上没有问题?
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
