将Blob从MySQL数据库导出到只有SQL的文件

编程入门 行业动态 更新时间:2024-10-11 11:13:21
本文介绍了将Blob从MySQL数据库导出到只有SQL的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个表格,图像数据存储在MySQL数据库的一个blob字段中。有没有办法通过仅使用SQL将这些图像导出到文件系统上的文件?图像应该命名为{imageId} .jpg

我知道使用Java或其他方法可以轻松实现,只需使用SQL脚本即可。 p>

解决方案

我不喜欢这个想法...

drop procedure if exists dump_image; 分隔符// 创建过程dump_image() begin 声明this_id int; 从图像中声明选择imageId的cur1游标; 打开cur1; read_loop:loop 将cur1转换为this_id; set @query = concat('select blob_field from image where imageId =', this_id,'into outfile/ tmp / xyz-',this_id,'。jpg'); 从@query准备write_file; 执行write_file; 结束循环; 关闭cur1; end // delimiter;

尽管出现错误

mysql>调用dump_image(); 错误1329(02000):没有数据 - 零行获取,选择或处理

ls -1 / tmp / xyz *

I have a table with image data stored in a blob field in a MySQL database. Is there a way to export those images to files on the filesystem by using only SQL? The images should be named {imageId}.jpg

I know that it is easy to do this with Java or whatever but is it possible with just a SQL script?

解决方案

I don't like the idea ...

drop procedure if exists dump_image; delimiter // create procedure dump_image() begin declare this_id int; declare cur1 cursor for select imageId from image; open cur1; read_loop: loop fetch cur1 into this_id; set @query = concat('select blob_field from image where imageId=', this_id, ' into outfile "/tmp/xyz-', this_id,'.jpg"'); prepare write_file from @query; execute write_file; end loop; close cur1; end // delimiter ;

Despite the error

mysql> call dump_image(); ERROR 1329 (02000): No data - zero rows fetched, selected, or processed

ls -1 /tmp/xyz*

更多推荐

将Blob从MySQL数据库导出到只有SQL的文件

本文发布于:2023-11-08 06:14:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   文件   导出到   Blob   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!