php 在 MySQL 中找不到 outfile 创建的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11484471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:38:00  来源:igfitidea点击:

Can't find the file created by outfile in MySQL

phpmysqlfilefile-io

提问by user1460822

I am using the following query to create a CSV file

我正在使用以下查询来创建一个 CSV 文件

SELECT email INTO OUTFILE "mydata.csv"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM users;

But i am unable to find the mydata.csv file anywhere when i am searching through filezilla.

但是当我搜索 filezilla 时,我无法在任何地方找到 mydata.csv 文件。

Any idea where this file is getting stored?

知道这个文件存储在哪里吗?

The query runs successfully without any errors! Any Help?

查询成功运行,没有任何错误!任何帮助?

回答by Michael Berkowski

MySQL may be writing the file into its own data directory, like /var/lib/mysql/<databasename>for example. To specify the path, use a full path.

MySQL 可能正在将文件写入它自己的数据目录,/var/lib/mysql/<databasename>例如。要指定路径,请使用完整路径。

However, it must be a directory that is writable by the user account the MySQL server daemon is running under. For that reason, I'll often use /tmp:

但是,它必须是运行 MySQL 服务器守护程序的用户帐户可写的目录。出于这个原因,我会经常使用/tmp

Specify the path you want to write to as in:

指定要写入的路径,如下所示:

INTO OUTFILE '/tmp/mydata.csv'

And note that MySQL will write the file on the MySQL server, not on your client machine. Therefore remote connections will create output files on the remote server. See also SELECT INTO OUTFILE local ?for more details and workarounds.

请注意,MySQL 会将文件写入 MySQL服务器,而不是您的客户端计算机上。因此远程连接将在远程服务器上创建输出文件。另见SELECT INTO OUTFILE 本地?有关更多详细信息和解决方法。

Systemd & Linux

系统与 Linux

A note about writing to /tmpon a Linux system running systemd:

关于/tmp在运行的 Linux 系统上写入的注意事项systemd

Some years after originally posting this, I found myself unable to locate a file written to /tmpvia

最初发布此内容几年后,我发现自己无法找到/tmp通过以下方式写入的文件

...INTO OUTFILE '/tmp/outfile.csv'

on a MariaDB 5.5 server running Fedora Linux with systemd. Instead of writing the file directly to /tmp/outfile.csvas specified, that directory and file were created beneath a systemd directory in /tmp:

在运行 Fedora Linux 的 MariaDB 5.5 服务器上systemd/tmp/outfile.csv该目录和文件不是按照指定直接写入文件,而是在以下 systemd 目录下创建/tmp

/tmp/systemd-mariadb.service-XXXXXXX/tmp/outfile.csv

While the file outfile.csvitself and the tmp/subdirectory were both created world-writable, the systemd service directory itself has 700 permissions and is root-owned, requiring sudoaccess to retrieve the file within it.

虽然文件outfile.csv本身和tmp/子目录都是可写的,但 systemd 服务目录本身具有 700 权限并且是 root 拥有的,需要sudo访问才能检索其中的文件。

Rather than specifying the absolute path in MariaDB as /tmp/outfile.csvand specifying it relatively as outfile.csv, the file was written as expected into MariaDB's data directory for the currently selected database.

不是将 MariaDB 中的绝对路径/tmp/outfile.csv指定为并将其相对指定为outfile.csv,而是按预期将文件写入 MariaDB 的当前所选数据库的数据目录中。

回答by Shlomi Noach

I suspect you are looking for the file on your client machine.

我怀疑您正在客户端计算机上查找该文件。

SELECT .. INTO OUTFILEwrites the file on the server machine.

SELECT .. INTO OUTFILE在服务器机器上写入文件。

回答by Neeraj Singh

Just for Example:

仅举例:

I have run below query in MySQL Workbench& I found my file in

我在MySQL Workbench 中运行了以下查询& 我在

SELECT * FROM `db`.`table` INTO OUTFILE 'file.csv' FIELDS TERMINATED BY ',';

D:\wamp\bin\mysql\mysql5.6.17\data\db\file.csv

D:\wamp\bin\mysql\mysql5.6.17\data\db\file.csv

You can use below example to set your file path:

您可以使用以下示例来设置文件路径:

SELECT * FROM `db`.`table` INTO OUTFILE 'C:\file.csv' FIELDS TERMINATED BY ',';

回答by StackG

I found my INTO OUTFILE files, created with the following command

我找到了使用以下命令创建的 INTO OUTFILE 文件

select name from users into outfile "name.csv"

select name from users into outfile "name.csv"

at the following location

在以下位置

C:\ProgramData\MySQL\MySQL Server 5.6\data\name.csv

C:\ProgramData\MySQL\MySQL Server 5.6\data\name.csv

This is probably the default location, as I've never changed anything.

这可能是默认位置,因为我从未更改过任何内容。

回答by seeker_of_bacon

In case anyone on OS X has this problem, mysqlinstalled with homebrew has default output located at /usr/local/var/mysql/database-name/

如果 OS X 上的任何人都有这个问题,mysql安装自制软件的默认输出位于/usr/local/var/mysql/database-name/

回答by WEBjuju

+1 to @michael-berkowski andthe answer i neededfor windows was (as he stated)

+1 @michael-berkowski我需要的 windows答案是(如他所说)

MariaDB's data directory

MariaDB 的数据目录

to be specific, mine was in the data folder for database named "mydatabase"

具体来说,我的位于名为“mydatabase”的数据库的数据文件夹中

C:\Program Files\MariaDB 10.3\data\mydatabase

C:\Program Files\MariaDB 10.3\data\mydatabase

回答by Naren

You find the file in C:\wamp\bin\mysql\mysql5.5.24\data, but the name will be UsersNamecarro.txtif you gave following select * from carro where id_cor<4 INTO OUTFILE 'C:\Users\Name\carro.txt';

您可以在 中找到该文件C:\wamp\bin\mysql\mysql5.5.24\data,但UsersNamecarro.txt如果您提供以下内容,则名称将为select * from carro where id_cor<4 INTO OUTFILE 'C:\Users\Name\carro.txt';

So just write .....OUTFILE 'C:\carro.txt'to get file called carro.txtin datafolder

所以只需写入.....OUTFILE 'C:\carro.txt'以获取文件夹中调用carro.txtdata文件