简体   繁体   English

mysql将数据导出到csv

[英]mysql export data to csv

I am using mysql **select into outfile.." export data to csv file, but in the mysql table there is a field of type "text" with some html content in the field. 我正在使用mysql ** select into outfile ..“将数据导出到csv文件,但是在mysql表中有一个“文本”类型的字段,该字段中带有一些html内容。

The content contains double quote(") and comma(,), so when I dump the data to csv,the text field will be spit to many fields when I open the csv file with office excel. 内容包含双引号(“)和逗号(,),因此当我将数据转储到csv时,当我使用office excel打开csv文件时,文本字段将被吐到许多字段中。

Some data in my table is just as following: 我表中的一些数据如下:

<div id="designer-txt-right">
                     <h2>TECHNICAL INFORMATION</h2>
                     <ul>
    <li>
        <strong><span lang="IT">Internal frame</span>: </strong><br>
        <span lang="IT">tubular steel and steel profiles</span></li>
    <li>
        <strong><span lang="IT">internal frame upholstery</span>: </strong><br>
        <span lang="IT"><span lang="IT">Bayfit® (Bayer®) flexible cold shaped polyurethane foam, cover in water repellent polyester fibre</span></span></li>
    <li>
        <strong><span lang="IT">Feet and fixing elements</span>: </strong><br>
        <span lang="IT"><span lang="IT">thermoplastic material</span></span></li>
    <li>
        <strong>COVER: </strong><br>
        FABRIC (<span lang="IT">limited categories)</span></li>
 </ul>
 <br>
                 </div>

My export sql statement: 我的导出sql语句:

SELECT * INTO OUTFILE '/tmp/filename.csv'  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'  LINES TERMINATED BY '\r\n' FROM product;

First check the content of the generated file in a text editor and make sure that the strings containing quotes and commas are in fact surrounded by quotation marks. 首先,在文本编辑器中检查生成文件的内容,并确保包含引号和逗号的字符串实际上被引号引起来。 I have sneaking suspicion that the file is generated correctly; 我怀疑是文件生成正确; however, the HTML content within it is sure to cause problems if you view the file in Excel. 但是,如果您在Excel中查看文件,其中的HTML内容肯定会导致问题。 The reason why is that the program, like many MS Office programs, sees HTML and then it tries to parse it as such. 原因是该程序像许多MS Office程序一样看到HTML,然后尝试将其解析为HTML。 This may cause more than a few problems viewing the file in Excel and there is not a good workaround for it. 这可能会导致在Excel中查看文件的多个问题,并且没有一个好的解决方法。 If you have other programs at your disposal that can use view the file, try it in those instead. 如果您有其他可以使用查看文件的程序,请改用这些程序。 You can also validate the content using CSV lint: http://csvlint.io/ 您也可以使用CSV短绒验证内容: http : //csvlint.io/

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

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