Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am writing a script to read data from a file by lines and insert each line into MySQL database. I use mysql.connector to do this. Here is a piece of script.

def insert_query(data):
    return ("INSERT INTO " + tblname + " (`log`) " + "VALUES " + "(" + "'" + data + "'" + ")")
with open('data.txt', 'r') as f:
    lines = f.readlines()

for line in lines:
    add_line = insert_query(line)
    cursor.execute(add_line)
    cursor.commit()

File data.txt has size is 5Mbyte, but it has about 10000 lines. tblname has 2 field: ID - INT (11) (auto-increment) , log - TEXT When i run this script, it add to database about 100 lines and crashed. It report a error:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for ')'

MySQL version : 5.5.27 How to solve this problem ? Thanks.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.