I try to use the Python library PyMySQL 0.9.3 on a Debian 10.3 server using Python 3.7.3 to connect to a local MariaDB 10.4.12 server.
~# pip3 show PyMySQL
Name: PyMySQL
Version: 0.9.3
Summary: Pure Python MySQL Driver
...
Location: /usr/local/lib/python3.7/dist-packages
~# python3 --version
Python 3.7.3
For test purpose, I created a database db1 and a user user1 on my MariaDB 10.4 server:
CREATE DATABASE db1 DEFAULT CHARSET utf8mb4;
GRANT ALL ON db1.* TO user1@localhost IDENTIFIED BY '1234';
I confirm that I can connect to db1 with the credentials above:
~# mysql -NB -hlocalhost -uuser1 -p1234 db1 -e "SHOW VARIABLES LIKE 'version'"
version 10.4.12-MariaDB-1:10.4.12+maria~buster-log
Now, let's create a Python script (test.py):
import pymysql.cursors
connection = pymysql.connect(host='localhost',
user='user1',
password='1234',
db='db1',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
=> Running this script leads to an error:
~# python3 test.py
Traceback (most recent call last):
File "test.py", line 15, in <module>
cursorclass=pymysql.cursors.DictCursor)
File "/usr/local/lib/python3.7/dist-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/pymysql/connections.py", line 325, in __init__
self.connect()
File "/usr/local/lib/python3.7/dist-packages/pymysql/connections.py", line 598, in connect
self._get_server_information()
File "/usr/local/lib/python3.7/dist-packages/pymysql/connections.py", line 975, in _get_server_information
packet = self._read_packet()
File "/usr/local/lib/python3.7/dist-packages/pymysql/connections.py", line 671, in _read_packet
% (packet_number, self._next_seq_id))
pymysql.err.InternalError: Packet sequence number wrong - got 1 expected 0
What's wrong with my setup? Did I missed some library or so? Or is PyMySQL incompatible with MariaDB 10.4?