Home > other >  For the great god of python mysql pymysql. Err. InternalError: Packet sequence number wrong - got 4
For the great god of python mysql pymysql. Err. InternalError: Packet sequence number wrong - got 4

Time:04-23

Pymysql. Err. InternalError: Packet sequence number wrong - got 45 expected 0
This error bothers me for a long time
Code:
The import pymysql
# connect to the database
Conn=pymysql. Connect (host='192.168.60.128', the port=22, user='root', passwd='123456', the db='mysql') # db: library name
# to create a cursor
Cur=conn. Cursor ()
# to insert a data
# reCount=cur. Excute (' insert into LCJ (name, age) vaules () % s, % s', (' ff ', 18))
# to test the library LCJ table insert
# ret=cur. Executemany (" insert into LCJ (name, tel) values (% s, % s) ", [(" kk ", 13212344321), (" kw ", 13245678906)])
# at the same time to insert multiple data in a database LCJ
Ret=cur. Executemany (" insert into LCJ values (% s, % s, % s, % s, % s) ", [(41, "xiaoluo41", 'man', 24132234332),
(42, "xiaoluo42", 'gril, 21132567948),
(43, "xiaoluo43", 'gril, 22132567949),
(44, "xiaoluo44", 'main', 24135324648)])
# submit
MIT ()
conn.com# close object pointer
Cur. Close ()
# closes the connection object
Conn. Close ()
# print the results
Print (ret)
~
Error Traceback (most recent call last) :
The File "C:/PycharmProjects//s14/day12/begin_pymysql py", line 3, the in & lt; module>
Conn=pymysql. Connect (host='192.168.60.128', the port=22, user='root', passwd='123456', the db='mysql') # db: library name
The File "C: \ Python \ Python36 \ lib \ site - packages \ pymysql \ set py", line 90, in the Connect
Return the Connection (* args, * * kwargs)
The File "C: \ Python \ Python36 \ lib \ site - packages \ pymysql \ connections py", line 688, in __init__
The self. The connect ()
The File "C: \ Python \ Python36 \ lib \ site - packages \ pymysql \ connections py", line 905, in the connect
Self. _get_server_information ()
The File "C: \ Python \ Python36 \ lib \ site - packages \ pymysql \ connections py", line 1207, in _get_server_information
Packet=self. _read_packet ()
The File "C: \ Python \ Python36 \ lib \ site - packages \ pymysql \ connections py", line 968, in _read_packet
(packet_number, self. _next_seq_id))
Pymysql. Err. InternalError: Packet sequence number wrong - got 45 expected 0

CodePudding user response:

Port=22???
Mysql the default port is 3306,
The default port 22 is SSH

CodePudding user response:

Whether to use the multithreading upstairs, if all threads share the same connection, please add mutex before each execute
Lock. Acquire ()
Cursor. The execute (command, data)
The lock release ()
Several kinds of solutions:
1. Each thread has its own connection
2. All threads share a connection, lock mutex using this link
3. All threads share a connection pool, you need to consider the total number of threads and the problem of connection pool upper limit of the number of connections

CodePudding user response:

CaiNiaoWuZui
Is truth, I also met this problem, thank CaiNiaoWuZui!

CodePudding user response:

CaiNiaoWuZui
Positive solution, I multithreaded operations DButils encapsulated mysql connection pool, and there is an error, and then use the connection pool in the scene before and after locking and releasing the lock

CodePudding user response:

refer to the second floor CaiNiaoWuZui response:
whether or not to use the multithreading, upstairs if all threads share the same connection, please add mutex before each execute
Lock. Acquire ()
Cursor. The execute (command, data)
The lock release ()
Several kinds of solutions:
1. Each thread has its own connection
2. All threads share a connection, lock mutex using this link
3. All threads share a connection pool, you need to consider the total number of threads and the problem of connection pool upper limit of the number of connections
approach is correct
  • Related