Newbie problem inserting into MySQL

John Nagle nagle at
Tue Aug 19 07:29:32 CEST 2008

len wrote:

> I have started a little pet project to learn python and MySQL.  The
> project involves figuring out all the combinations for a 5 number
> lottery and storing the data in a MySQL file.

    1.  As someone else mentioned, the placeholder for MySQL data
	is "%s", not "?".
    2.  After inserting, you must call "db.commit()", or, when the
	program exits, all the insertions will be backed out.
	(Assuming you're using a table type that supports
	transactions, like InnoDB.  But commit anyway.)
    3.  If you're inserting a huge number of records, look into
	LOAD DATA.  It's much faster.
    4.  Your code will make 10000 entries, then exit.  Is that
	what you want?
    5.  Creating a database of computed values is a useful exercise,
	but not all that useful.

				John Nagle

More information about the Python-list mailing list