可以 select ... into outfile 不将其保存到文件中,而是将其保存在 blob 中

发布于 2024-11-02 14:08:35 字数 353 浏览 3 评论 0原文

我想要执行 select * from x into outfile 'c:/test.csv'
但我不想将其保存到输出文件 test.csv 中,而是将其保存到 blob 字段中。

我正在从 Windows 上的客户端启动查询。
MySQL 服务器位于 Windows 或 Linux(可以是两者)上的服务器上。
但我希望该文件位于客户端,而不是服务器上的某个位置。

顺便说一句
客户端软件用Delphi 2007编写,并使用ZEOS连接到远程服务器上的MySQL数据库。

如何获取输出文件客户端而不是服务器端?

I want to do a select * from x into outfile 'c:/test.csv'.
But instead of saving into an outfile test.csv I want to save it into a blob field.

I'm starting the query from a client on Windows.
The MySQL server is on a server on Windows or Linux (can be both).
But I want to have the file client-side, not somewhere on the server.

BTW
The client software in written in Delphi 2007 and uses ZEOS to connect to the MySQL database on a remote server.

How do I get the outfile client side, instead of server side?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时常饿 2024-11-09 14:08:35

Johan,MySql 从运行的服务器上执行这句话。在客户端创建文件的唯一方法是传递指向客户端计算机的共享文件夹位置和文件名。 MySQL 服务(守护进程)所有者还必须拥有足够的权限才能写入目标目录。

来自Mysql 文档

SELECT ... INTO OUTFILE 语句
主要是为了让你非常
快速将表转储到文本文件
服务器机器。如果你想
在某些上创建结果文件
除了服务器主机之外的其他主机,您
通常不能使用 SELECT ... INTO
OUTFILE 因为没有办法写
相对于文件的路径
服务器主机的文件系统。

但是,如果MySQL客户端软件
安装在远程计算机上,
您可以改为使用客户端命令
如 mysql -e "SELECT ..." >
file_name 在上生成文件
客户端主机。

也可以创建
不同主机上的结果文件
除了服务器主机之外,如果
文件在遥控器上的位置
可以使用访问主机
服务器上的网络映射路径
文件系统。在这种情况下,
mysql(或其他一些 MySQL
客户端程序)不需要
目标主机。


Johan, MySql executes this sentence from the server where is running. the only way to create the file in the client side is passing a shared folder location and file name which points to the client machine. also the MySQL service (daemon) owner must possess adequate privileges to write to the target directory.

from the Mysql Documentation

The SELECT ... INTO OUTFILE statement
is intended primarily to let you very
quickly dump a table to a text file on
the server machine. If you want to
create the resulting file on some
other host than the server host, you
normally cannot use SELECT ... INTO
OUTFILE since there is no way to write
a path to the file relative to the
server host's file system.

However, if the MySQL client software
is installed on the remote machine,
you can instead use a client command
such as mysql -e "SELECT ..." >
file_name to generate the file on the
client host.

It is also possible to create the
resulting file on a different host
other than the server host, if the
location of the file on the remote
host can be accessed using a
network-mapped path on the server's
file system
. In this case, the
presence of mysql (or some other MySQL
client program) is not required on the
target host.

最丧也最甜 2024-11-09 14:08:35

好的,如果人们想知道,我对 TMS DBAdvGrid 做了一个解决方法来导出 CSV 文件。

我向 TAdvStringGrid 添加了一个新属性

public {properties}
property HideCSVHeader: boolean read FHideCSVHeader write FHideCSVHeader;

并更改了以下代码:

procedure TAdvStringGrid.OutputToCSV(FileName:String;appendmode: Boolean; 
  Unicode: boolean);
....
//changed this code further down the procedure:
//for z := SaveStartRow to SaveEndRow do 
//Into:

MyStartRow:= SaveStartRow;
if HideCSVHeader then Inc(MyStartRow);
for z := MyStartRow to SaveEndRow do   

然后当我调用

procedure TForm1.BtnExportClick(Sender: TObject);
var
  Filename: string;
  succes: Boolean;
begin
  succes:= True;
  if ExportSaveDialog.Execute then begin
    Filename:= ExportSaveDialog.FileName;
    try
      DBGridExportExact.Delimiter:= ';';
      DBGridExportExact.AlwaysQuotes:= True;
      DBGridExportExact.QuoteEmptyCells:= True;
      DBGridExportExact.SaveHiddenCells:= True;
      DBGridExportExact.HideCSVHeader:= True;
      DBGridExportExact.SaveToCSV(bestandsnaam);
    except
      succes:= False;
    end;
    if not(succes) then StatusLabel.Caption:= 'Error bla bla';
  end;
end;

OK In case people want to know I made a workaround to the the TMS DBAdvGrid to export the CSV file.

I added a new property to TAdvStringGrid

public {properties}
property HideCSVHeader: boolean read FHideCSVHeader write FHideCSVHeader;

and changed the following code:

procedure TAdvStringGrid.OutputToCSV(FileName:String;appendmode: Boolean; 
  Unicode: boolean);
....
//changed this code further down the procedure:
//for z := SaveStartRow to SaveEndRow do 
//Into:

MyStartRow:= SaveStartRow;
if HideCSVHeader then Inc(MyStartRow);
for z := MyStartRow to SaveEndRow do   

Then when I call

procedure TForm1.BtnExportClick(Sender: TObject);
var
  Filename: string;
  succes: Boolean;
begin
  succes:= True;
  if ExportSaveDialog.Execute then begin
    Filename:= ExportSaveDialog.FileName;
    try
      DBGridExportExact.Delimiter:= ';';
      DBGridExportExact.AlwaysQuotes:= True;
      DBGridExportExact.QuoteEmptyCells:= True;
      DBGridExportExact.SaveHiddenCells:= True;
      DBGridExportExact.HideCSVHeader:= True;
      DBGridExportExact.SaveToCSV(bestandsnaam);
    except
      succes:= False;
    end;
    if not(succes) then StatusLabel.Caption:= 'Error bla bla';
  end;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文