我正在尝试加载几个txt文件并将它们插入到mysql中:这是我的代码:
result = os.listdir("C:/path/")
for x in result:
db = MySQLdb.connect("localhost", "root", "Mydatabases#0", "myblog",local_infile=True)
cursor = db.cursor()
file1 = os.path.join('path'+x)
cursor.execute("insert into clamp (sample) values (LOAD_FILE(%s),(file1))")
db.commit()
db.close()
但是我收到了这个错误:
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s),(x,))' at line 1")
nsomeone可以告诉我我的代码有什么问题吗? 谢谢,
答案 0 :(得分:0)
以下是我需要使用的代码: cursor.execute(“insert into clamp(sample)values(LOAD_FILE(%s))”,(file1,))