通过 MySQL 创建 CSV 文件 - 有任何限制吗?
我将通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内存应该不是问题,但您需要确保写入的卷可以处理那么大的文件。我见过很多人陷入 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.