将 blob 行从 MySQL 转储到文件 [英] Dumping blob rows to files from MySQL

查看:94
本文介绍了将 blob 行从 MySQL 转储到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含几千行的表,其中有几个整数列和一个 blob 列.我想将每一行作为自己的文件转储出来,其中 blob 是内容,整数用于形成文件名.这是一次操作,如此快速和肮脏是可以的.一个限制是我在这个环境中几乎没有安装任何工具,所以无论我使用什么,这都将成为开发成本的一部分.

I have a table with a few thousand rows in it that has a few integer columns and a blob column. I want to dump each row out as its own file with the blob being the content and the integers being used to form the file name. This is a one time op so quick and dirty is OK. One constraint is that I have almost no tools installed in this enviornment so that will be part of the dev cost no matter what I use.

我最终使用了另一个盒子中的 C#.只需要下载一个程序集和大约相同数量的代码如以下答案所示.

I ended up using C# from another box. It only took downloading a single assembly and about the same amount of code as given in the answers below.

推荐答案

PHP 中的一些快速方法:

Something quick in PHP:

<?php
$connection = mysql_connect("mysqlserver.example.com", "username", "password");
mysql_select_db("dbname");
$sql = "SELECT `blob_column`, `id` FROM `mytable`";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
    file_put_contents("file" + $row["id"] + ".dat", $row["blob_column"]);
}
mysql_close($connection);

您可能可以使用任何必须访问 MySQL 的方法来做一些类似的事情,但是 AFAIK,没有办法使用纯 SQL 来做到这一点.

You could probably do something simular with whatever method you have to access MySQL, but AFAIK, there's no way to do it with pure SQL.

这篇关于将 blob 行从 MySQL 转储到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆