Search code examples
mysqlpython-3.xmysql-connector

Get command executed by python mysql connector


I am using mysql connector with python, and sometimes when debugging I would like to see what command the cursor have executed exactly. I have things like this:

 ajout="UPDATE campagne_detail set fait_CAMD=1 WHERE id=%s and ca=%s"
 val=(a,b)
 cursor.execute(ajout,val)

How can I do to see exactly what command it sent to mysql?

Thanks


Solution

  • After executing the statement, call

    sql = cursor.statement
    

    sql will be the string sent to the MySQL server.