使用 python 自动填充 mysql 数据库

auto filling mysql database using python

我想使用 python 自动填充数据库 我有 table 4 列 id 姓名 lastname 手机号码 我正在从文本文件中输入姓名和姓氏。 这是我正在尝试的

with open("names.txt") as f:
    word=f.read()
    word=word.split()
with open ("last name.txt") as l:
    wordx=l.read().split()
    print(wordx)
for (i,j,k) in zip(range(3,12),word,wordx):
    insertdata="insert into person(id,firstname,lastname,mobileno) values ('%d','%r','%r','%d')"%(i,tuple(word),tuple(wordx),randint(0000000000, 9999999999))
    cursor.execute(insertdata)
    connectionvar.commit()

我收到这个错误 pymysql.err.ProgrammingError: (1064, "您的 SQL 语法有误;请查看与您的 MariaDB 服务器版本对应的手册以获得正确的语法

得到答案:)

with open("names.txt") as f:
    word=f.read()
    word=word.split()
with open ("last name.txt") as l:
    wordx=l.read().split()
    print(wordx)
for (j,k) in zip(word,wordx):
    insertdata="insert into person(firstname,lastname,mobileno) values ('%s','%s','%d')"%(j,k,randint(0000000000, 999999999))
    cursor.execute(insertdata)
    connectionvar.commit()