简体   繁体   English

MySQL长文本字段导出到CSV Excel

[英]MySQL Long Text Field Export to CSV Excel

I'm trying to get data out of MySQL table and into a csv so I can edit in Excel. 我正在尝试从MySQL表中获取数据并导入到csv中,以便可以在Excel中进行编辑。

There is a note field that is extremely long and has a ton of different characters. 有一个非常长的注释字段,其中包含许多不同的字符。

When I open the file in excel it throws the data all out of place. 当我在excel中打开文件时,它会将数据全部丢掉。 Any ideas on how to get this file out of mysql and keep all the rows aligned? 关于如何从mysql中获取此文件并保持所有行对齐的任何想法?

Please and thank you. 谢谢,麻烦您了。

Use the query below 使用下面的查询

LOAD DATA INFILE 'data.csv' INTO TABLE tbl_name
FIELDS ENCLOSED BY '#' TERMINATED BY ';'  LINES TERMINATED BY '\r\n';

Note 注意

For a text file generated on a Windows system, proper file reading might require LINES TERMINATED BY '\\r\\n' because Windows programs typically use two characters as a line terminator. 对于在Windows系统上生成的文本文件,正确的文件读取可能需要以LINES TERMINATED BY '\\r\\n'结尾的行,因为Windows程序通常使用两个字符作为行终止符。 Some programs, such as WordPad, might use \\r as a line terminator when writing files. 某些程序(例如写字板)在写入文件时可能使用\\r作为行终止符。 To read such files, use LINES TERMINATED BY '\\r' . 要读取此类文件,请使用LINES TERMINATED BY '\\r'

More details can be found in the MYSQL documentation . 可以在MYSQL 文档中找到更多详细信息。

A good practice in this case might be to normalize the data in the notes field? 在这种情况下,一个好的实践可能是规范注释字段中的数据? REPLACE(REPLACE(table.notes, '\\r', ''), '\\n', '')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM