gpt4 book ai didi

Python:加载数据 INFILE mySQL

转载 作者:行者123 更新时间:2023-11-30 22:56:34 29 4
gpt4 key购买 nike

我尝试使用 Python 将数据导入 mySQL 数据库,但无法正常工作。我没有收到任何错误,看起来一切正常,但文本文件永远不会被导入。

如果我通过终端中的 mysql 命令行手动导入文本文件,我可以很好地导入它。我做错了什么?

imoprt mysql.connector
cnx = mysql.connector.connect(user ='user1', password ='12345', host ='127.0.0.1', database ='stockStatus')
cursor = cnx.cursor()
cursor.execute('use stockStatus')
cursor.execute('truncate table products')
cursor.execute("LOAD DATA INFILE '/Path/products.txt' INTO TABLE products IGNORE 1 LINES")
cnx.close()

最佳答案

尝试在输入文件名周围使用双引号:

cursor.execute('LOAD DATA INFILE "/Path/products.txt" INTO TABLE products IGNORE 1 LINES')

关于Python:加载数据 INFILE mySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26123660/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com