Search code examples
pythonmysql-workbenchmysql-pythonmysql-connector-python

Insert data in to mysql db using mysql.connector


I'm trying to insert some data into the table "billing accounts" and I tried the given below way. There was no error, how ever the data is not getting inserted into the table. am I doing anything wrong here? I am using python's mysql.connector module for this work.

def billingaccounts(self,stag,prod):

    print "Updating the consilidated daily bills for stag and prod"
    cursor = self.testdb.cursor()
    stag = 87
    prod = 45
    now = '2016-06-03'
    to = 84
    cursor.execute('INSERT INTO iaas.billing_accounts (date, staging_account, production_acount, total) VALUES (%s, %s, %s, %s)',(now,stag,prod,to))

Solution

  • You have to send a commit to the server to see the changes.

    https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-commit.html