从独立文件导入 - MySQL Workbench

问题描述 投票:0回答:1

描述:

我在 MySQL Workbench 中导入 Excel 文件时遇到问题(数据导入/恢复< Import from Disk < Import from Self-Contained File < choose Target Schema < Start Import) containing two tables with four columns and 超过 50000 行。

数据集:

例如,我的 Excel 表格如下所示:

列表_ID 列表_Parent_ID 行动 日期时间
1421853 1421853 在线 2010/01/31 23:40:03
1382755 1382755 在线 2010年1月19日23:40:00

错误信息:

ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: 'PK'.

备注:

我尝试了(如何使用 MySQL 中的命令行导入 SQL 文件?)和(如何将 excel 文件导入到 MySQL 数据库)中建议的一些工具;但出现以下问题:

  1. 数据转换器,获取 Excel 文件;但是数据时间的结果不正确,我的查询遇到了错误:

INSERT INTO DailyList   (List_ID, List_Parent_ID, Action, DateTime) VALUES   (1392893,1392893,'ONLINE','1/3/2010 23:40') Error Code: 1292. Incorrect datetime value: '1/3/2010 23:40' for column 'DateTime' 

  1. SQLizer.io 对于最多 5000 行的任何内容都是免费的。

期望:

理想情况下,我正在寻求将所有行和列以正确格式成功导入到 MySQL Workbench 中。

excel import mysql-workbench
1个回答
0
投票

这里我想详细说明一下我如何在MySQL Workbench 8.0中成功转换我的文件:

输入数据: Excel 文件,其中包含一个表格(列表),其中包含字符串中的日期时间 步骤

  1. 将 Excel 文件转换为 CSV(右键单击并将其另存为 CSV)

  2. 使用 Pandas 将 DateTime 转换为所需的格式

    将 pandas 导入为 pd dataset_paths = '日志.csv'

    df = pd.read_csv(数据集路径) df['DateTime'] = pd.to_datetime(df['DateTime'], format="%m/%d/%Y %H:%M") df.drop_duplicates(inplace=True) df.to_csv('updated_file_logs.csv',index=False)

  3. 在方案中选择一个表< click Table Data Import Wizard < select file to import < select destination table (查看答案以获取更多信息

© www.soinside.com 2019 - 2024. All rights reserved.