Python MySQL prepared statements slower than regular queries I'm trying to use prepared statements with python to improve query performance, but my prepared statements are slower (by a factor of ~7.5 no matter how many iterations I set in my benchmark script).

Here is a small benchmark script I wrote:

In essence what I do for regular queries:

cursor = connection.cursor()
cursor.execute("INSERT into test (id,name) VALUES (1,'Value 1')")
... multiple inserts ...
connection.commit()


And for prepared statements:

cursor = connection.cursor(prepared=True)
sql = "INSERT into test (id,name) VALUES (%s,%s)"
cursor.execute(sql, (1, 'Value 1'))
... multiple inserts ...
connection.commit()



The script runs 2 loops with same number of iterations
1st loop runs with the default .cursor() while 2nd with .cursor(prepared=True) as per above


And here are the results:



As you can see MySQLCursorPrepared=9746ms while MySQLCursor=1299ms.

Why are my prepared statements slower than regular queries? Is it an issue with the python mysql.connector driver or do I need to tweak something in my MySQL config to fix this?
Much faster is to build a multi-row insert:

INSERT INTO t (a,b)
    VALUES
    (1,2),
    (11,23),
    (111,234), ...


On the MySQL side, this runs about 10 times as fast (for 100-1000 rows) than single-row inserts.