Sha*_*are 19
假设您INTO在要存储文件的位置具有写入权限,则可以执行以下操作:
SELECT id, blob INTO DUMPFILE '/tmp/path' FROM table;
Run Code Online (Sandbox Code Playgroud)
不幸的是,在MySQL中,无法将dumpfile指定为表达式/变量.但是,如果将其包装在存储过程中并使用变量,则可以实现此目的.
ajr*_*eal 14
我不喜欢这个主意......
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 ;
Run Code Online (Sandbox Code Playgroud)
尽管有错误
mysql> call dump_image(); ERROR 1329 (02000): No data - zero rows fetched, selected, or processed
ls -1 /tmp/xyz*
| 归档时间: |
|
| 查看次数: |
52273 次 |
| 最近记录: |