Function to store data in MySQL database (using OurSQL)
You might want to try doing everything inside a transaction. It may be faster that way. I think with InnoDB you might be creating a committing a transaction for every statement which will be slow.

keys = str(tuple(keys)).replace("'", "")


That's an odd way of doing that, use

keys = '(%s)' % ','.join(keys)