I am developing a program in Python that accesses a MySQL database using MySQLdb. In certain situations, I have to run an INSERT or REPLACE command on many rows. I am curren
Your first example is a single (large) statement that is generated and then sent to the database.
The second example is a much simpler statement that inserts/replaces a single row but is executed multiple times. Each command is sent to the database separately so you have to pay the turnaround time from client to server and back for every row inserted. I would think that this extra latency introduced between the commands is the main reason for the decreased performance of the second example.