php - 将 CSV 导入 MySQL Workbench,其中文本字段包含数据换行符

标签 php mysql csv upload mysql-workbench

尝试使用解决方案将 csv 从电子表格加载到 MySQL Workbench found here

LOAD DATA LOCAL INFILE '/path/to/your/csv/file/model.csv' INTO TABLE test.dummy FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

数据已加载,但电子表格中的某些单元格已包含换行符。在这些情况下,LOAD 创建了一条新记录。

Mathematics Kindergarten,Counting,"Say the number sequence 0 to 1000 forward and backward by:
- 5s, 10s or 100s, using any starting point 
- 3s, using starting points that are multiples of 3
- 4s, using starting points that are multiples of 4
- 25s, using starting points that are multiples of 25."

使用类似以下格式的表格:

 Course   |   Topic    | Description

数据加载如下:

Mathematics Kindergarten   |    Counting    | "Say the number sequence 0 to 1000 forward and backward by:
- 5s, 10s or 100s, using any starting point              |                | 
- 3s, using starting points that are multiples of 3      |                | 
- 4s, using starting points that are multiples of 4      |                | 
- 25s, using starting points that are multiples of 25."  |                | 

如何让系统识别加载数据,以便整个单元格包含完整的描述,并且不会因 X 条记录而中断。

最佳答案

这些步骤让我返回到导出 CSV 的文档。我必须清理数据。

查找单元格中存在的回车换行字符并将其替换为\n。 还发现其他一些单元格在 html 编号 ,

中包含逗号 ,

这纠正了 MySQL Workbench 数据导入工具的问题。

关于php - 将 CSV 导入 MySQL Workbench,其中文本字段包含数据换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43147569/

相关文章:

php - 在 Moodle 3.5 中添加新用户时出错

php - 在 Mysql 数据库中的新数据行之前插入空白行

excel - Office 365 上的 CSV 文件

c++ - 如何从 C++ 中的文件流中检测行的结尾

Python-按常量列标题排列 CSV 文件的不同行

php - curl 的多个请求(不是 'multi-threaded')

php - 重用、重写或重构?

php - 每 30 天范围内的列计数

php - MySQL:获取表的所有以名称 "ctr_"和值 1 开头的列

MySql 获取游标到变量返回空