您可以使用Python的MySQL连接库,如mysql-connector-pythonPyMySQL来连接MySQL数据库,并使用SQL语句将数据批量导入数据库。下面是一个示例代码:

import mysql.connector

# 连接MySQL数据库
conn = mysql.connector.connect(
    host="your_host",
    user="your_user",
    password="your_password",
    database="your_database"
)

# 创建游标对象
cursor = conn.cursor()

# 定义要导入的数据
data = [
    (1, "text1", "document1"),
    (2, "text2", "document2"),
    (3, "text3", "document3")
]

# 批量导入数据
sql = "INSERT INTO your_table (id, text, document) VALUES (%s, %s, %s)"
cursor.executemany(sql, data)

# 提交更改
conn.commit()

# 关闭游标和连接
cursor.close()
conn.close()

请注意替换代码中的以下部分:

  • your_host:MySQL数据库的主机名或IP地址
  • your_user:MySQL数据库的用户名
  • your_password:MySQL数据库的密码
  • your_database:MySQL数据库的数据库名
  • your_table:要导入数据的表名

将上述代码中的data替换为您要导入的实际数据即可。每个元组代表一行数据,元组中的每个元素分别对应于表的不同列。

确保您已经安装了所选择的MySQL连接库,并在代码中正确导入该库

mysql数据库里面批量导入data参数字段有idtextdocument用Python写

原文地址: http://www.cveoy.top/t/topic/hShE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录