将 mysql 表导出到 csv

发布于 2024-12-15 04:46:21 字数 235 浏览 3 评论 0原文

我正在使用 sqlyog 并尝试将表的数据导出到 csv。我用于导出的设置是:

  • 转义符: \ 行
  • 终止符: \r\n
  • 可变长度: 字段终止符: , , 封闭的字段: " 可选

问题是我的某些字段包含带有 " 的数据,例如会议地点为“Plaza hotel”。这会“损坏”数据并且字段不会按应有的方式显示。有什么办法可以解决这个问题吗?

非常感谢!

I am using sqlyog and trying to export the data of a table to csv. The settings I use for exporting are:

  • Escaped by: \
  • Lines terminated by: \r\n
  • Variable length: Fields terminated by: , ,Fields enclosed by: " Optionally

The problem is that some of my fields contain data with ", e.g. The place of the meeting is at "Plaza hotel". This "corrupts" the data and the fields are not shown as they should be. Is there a way I can fix this?

Thank you very much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由如风 2024-12-22 04:46:21

请参阅 MySQL 文档: http://dev .mysql.com/doc/refman/5.0/en/string-syntax.html#character-escape-sequences

用“””引用的字符串内的“””可以写成“”””。

因此使用双引号作为“转义字符”。

Refer MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html#character-escape-sequences

A “"” inside a string quoted with “"” may be written as “""”.

So use Double-quotes as "Escape Character".

帥小哥 2024-12-22 04:46:21

假设我们有这样的查询:

SELECT name, email, age
FROM
users
WHERE status = 'Active';

因此,如果我们需要将此数据导出到 csv 文件中,那么使用以下查询我们可以执行以下操作:

SELECT name, email, age
FROM
users
WHERE status = 'Active'
INTO OUTFILE 'C:/xampp/users.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';

Suppose we have a query like:

SELECT name, email, age
FROM
users
WHERE status = 'Active';

So if we need to export this data into a csv file then using below query we can do:

SELECT name, email, age
FROM
users
WHERE status = 'Active'
INTO OUTFILE 'C:/xampp/users.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文