通过 MySQL 创建 CSV 文件 - 有任何限制吗?

发布于 2024-11-05 08:49:41 字数 297 浏览 0 评论 0原文

我将通过 MySQL 创建一些 CSV 文件,代码如下所示。

SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM users WHERE 1

但我只是想知道生成的文件是否会相当大(可能有几个 GB),是否有我应该关心的事情或预防措施我应该带?比如记忆力问题等?

I am going to be creating some CSV files via MySQL with code like the below for example..

SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM users WHERE 1

But I was just wondering if the resulting file is going to be rather large (possibly several GB's) is there things I should be concerned about or precautions I should take? Like memory problems etc?

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

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

发布评论

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

评论(1

-柠檬树下少年和吉他 2024-11-12 08:49:41

内存应该不是问题,但您需要确保写入的卷可以处理那么大的文件。我见过很多人陷入 2GB 或 4GB 的困境,因为他们的文件系统无法处理比这更大的文件。

另外,我建议将其写入 MySQL 计算机上的本地驱动器,然后通过网络或其他方式复制。如果您的网络至少不是千兆位,则写入这么大的文件可能需要相当长的时间。

还有一个建议...首先在大约 1000 行左右尝试,然后针对目标环境测试您的 CSV。有时需要多次尝试才能将格式设置为您想要的位置。

Ram shouldn't be an issue, but you'll want to make sure the volume you are writing it to can handle that large of a file. I've seen a lot of guys get stuck at 2GB or 4 GB because their file system couldn't handle files larger than that.

Also, I recommend writing it to a local drive on the MySQL machine and then copying it over the network or other means. Writing that large of a file could take quite a while if your network isn't at least Gigabit.

One more suggestion... try it on about 1000 rows or so first, and then test your CSV against your target environment. Sometimes it takes a few tries to get the formatting where you want it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文