问题
I checked different post like: Is there a way to use 'pool_reset_connection' from mysql-connector-python with MariaDB 10.4.7?
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.
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?
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.
回答1:
It's a problem how MySQL Connector/Python detects the server version:
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.
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.
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
)
来源:https://stackoverflow.com/questions/61173405/why-mysql-connector-works-without-problem-with-python2-7-and-not-with-python3