将图像从 MySQL 卸载到磁盘
我将图像作为 blob 存储在 MySQL 中(我知道这是错误的)。而且有很多。有没有一种快速的方法可以将它们全部放到磁盘上,例如 SELECT .. INTO OUTFILE ,但可以将多个文件插入一个文件?或者唯一的方法是编写一个可以迭代行并保存图像的脚本?
I have images stored in MySQL as blobs (i know it's wrong). And there are many of them. Is there any fast way to drop them all on disk, like SELECT .. INTO OUTFILE
, but to many files insted of one? Or the only way is writing a script that will iterate over rows and save images?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您希望将它们保存到磁盘上的不同文件中,因此您必须使用脚本。
Since you want them to be saved into different files on the disk you'll have to go for a script.
我有一个类似的要求,我发现在我的案例中使用 Java + Hibernate(在其他 Hibernate 变体中可能有类似的任务,但没有尝试过),很快就让我到达了那里。
我设置了一个像这样的映射:
一个用于携带数据的Java bean,类似于:
和一个类似这样的循环:
还有一些东西(我称之为“ExtractBlob”)来提取blob(使用PK来生成一个文件名),像这样:
...
;
...
如果您认为它可能有用,我可以发布一个更完整的示例 - 但我会从更大的项目中提取代码,否则我会直接发布它。
I had a similar requirement , I found in my case using Java + Hibernate (possibly similar task in other Hibernate variations, but not tried it), got me there quite quickly.
I set up a mapping like this:
A Java bean to carry the data, something like:
And a loop something like this:
And something ("ExtractBlob" is I'm calling this) to extract the blob (using the PK to generate a filename), something like this:
...
;
...
I can post a more complete example if you looks like it might be useful - but I would have extract the code from a bigger project, otherwise I would have just posted it straight up.