Python couldn't insert row to MySQL

I'm trying to accomplish following query:

sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES (% (ua) s,% (ru) s);"
data = {'ua': 'ukrainian', 'ru': 'russian'}
cursor.execute (sql, data)

After executing this query, there is no such record in table.

If do the same query in SQLyog, record will exists.

I've also tried:

sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123 ', '333');"
cursor.execute (sql)
print sql

and there is no row in the table.

The console displays : INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123 ', '333');

Executing this query in SQLyog, normally inserts a row in the table.

I've created another table with the same structure.

Can someone help me, please?


You need to cursor.commit() to reflect changes.

9.2.3. Method MySQLConnection.commit()

This method sends a COMMIT statement to the MySQL server, committing the current transaction. Since by default Connector/Python does not autocommit, it is important to call this method after every transaction that modifies data for tables that use transactional storage engines.

Need Your Help

In-order traversal of unthreaded binary search tree, without a stack

algorithm tree binary-tree binary-search-tree

Suppose that we somehow get a dump of an alien computer's memory. Unfortunately, said alien civilization had much large RAM sizes than we have, and somehow loved functional languages so much that a...

Swift / OS X : Transform is not available

swift transform

When developing for iOS I can use the transform command with success but when developing for OS X transform is not available .. Here is the line i am having problem with: