

You will store your values in 1-dimensional numpy arrays arr_name and arr_email which are then converted in a list of concatenated values, row by row. There is a chance that this solution has the high speed of answer without risking injection attacks.
Python insert into mysql how to#
I looked at using LOAD DATA INFILE, but I really don't understand how to format the file or the query and my eyes bleed when I have to read MySQL docs. The list is huge and I definitely can't afford to put the insert into a loop. What am I doing wrong? Is this even possible? This is the error: _mysql_exceptions.OperationalError: (1241, 'Operand should contain 1 column(s)') I tried putting my query into a var initially, but then it just barfed up a message about passing a tuple to execute(). email is the 4th col."""įor n, e in sorted(mailing_eritems()):ĭb = nnect(host=host, user=user, db=dbname, passwd=pwd)Ĭursor.execute("""INSERT INTO mailing_list (name,email) VALUES (%s,%s)""", Obviously I don't want to do an insert statement for every list item. Now I want to put each name and email into a mysql database. I am using python with xlrd to retrieve the name and email from the xls file into two lists. Does anybody know why there is a type error now? TypeError: not all arguments converted during string formatting The error message reads: query = query % db.literal(args)
Python insert into mysql code#
After passing execute() a list of rows as per Nathan's suggestion, below, the code executes further but still gets stuck on the execute function.
