Mysql outfile 到当前工作目录?
有没有办法使 .sql 文件中的 OUTFILE 语句指向 .sql 文件本身的当前工作目录的路径,而无需手动指定绝对路径名? 现在,默认位置是我正在使用的模式的数据目录(即 C:\progra~1\mysql\etc\etc)。
谢谢!
Is there a way I can make the OUTFILE statement in a .sql file point to the path of the current working directory of the .sql file itself, without manually specifying an absolute path name? As it is now, the default location is the data directory of the schema that I'm working with (ie. C:\progra~1\mysql\etc\etc).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来编写脚本是你最好的选择。 使用 Perl 或 PHP 生成带有 cwd 中的输出文件的查询。
Seems like scripting would be your best bet on this. Using Perl or PHP to generate the query with the outfile in cwd.
不能直接使用,但您可以通过在命令行中使用 mysql 来获得类似的功能。
首先,一些背景知识:
LOAD DATA INFILE
语句有一个LOCAL
变体,LOAD LOCAL DATA INFILE
,它允许您读取< /em> 来自本地文件系统上文件的数据; 如果没有LOCAL
,它会从服务器上的指定位置读取。不幸的是,
SELECT INTO OUTFILE
语句总是写入服务器文件系统上的指定位置(其中可以包括服务器配置的挂载,例如NFS 或 CIFS 共享); 没有LOCAL
等效项。但是,您可以通过在批处理模式下使用
mysql
客户端来实现这样的功能:-B
选项使语句以批处理模式运行,因此查询结果以制表符分隔的方式打印,没有边框。 使用<代码>> somefile.txt 允许您将该输出重定向到指定的文件,因此您可以获得与您想要的等效的内容,而无需FIELDS
或LINES
选项code>SELECT INTO OUTFILE,但足够接近了!Not directly, but you can get similar functionality by using
mysql
at the command line.First, some background: the
LOAD DATA INFILE
statement has aLOCAL
variant,LOAD LOCAL DATA INFILE
, that allows you to read data from a file on your local file system; withoutLOCAL
it reads from the specified location on the server.Unfortunately, the
SELECT INTO OUTFILE
statement always writes to the specified location on the server's filesystem (which can include server-configured mounts such as NFS or CIFS shares); there is noLOCAL
equivalent.However, you can approximate such functionality by using the
mysql
client in batch mode:The
-B
option causes the statement to run in batch mode, so the query results are printed in a tab-delimited way, with no borders. Using> somefile.txt
allows you to redirect that output to the specified file, so you have something equivalent to what you want, without theFIELDS
orLINES
options ofSELECT INTO OUTFILE
, but close enough!