MySQL通过一种被称为“压缩协议”的机制来压缩其响应。压缩协议使用 zlib 库来压缩数据,可通过使用 CLIENT_COMPRESS 客户端标志启用该功能。
以下是一个MySQL的Python代码示例,展示了如何使用 MySQL 的 Python 连接器中的客户端压缩协议:
import mysql.connector
cnx = mysql.connector.connect(user='username', password='password', host='127.0.0.1', database='mydb', client_flags=[mysql.connector.ClientFlag.COMPRESS])
cursor = cnx.cursor()
query = "SELECT * FROM mytable"
cursor.execute(query)
for row in cursor.fetchall():
print(row)
cursor.close()
cnx.close()