問題描述
我正在使用以下查詢來創建 CSV 文件
I am using the following query to create a CSV file
SELECT email INTO OUTFILE "mydata.csv"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "
"
FROM users;
但是當我搜索 filezilla 時,我無法在任何地方找到 mydata.csv 文件.
But i am unable to find the mydata.csv file anywhere when i am searching through filezilla.
知道這個文件的存儲位置嗎?
Any idea where this file is getting stored?
查詢運行成功,沒有任何錯誤!有什么幫助嗎?
The query runs successfully without any errors! Any Help?
推薦答案
MySQL 可能正在將文件寫入自己的數據目錄,例如 /var/lib/mysql/
.要指定路徑,請使用完整路徑.
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 服務器守護程序的用戶帳戶可寫的目錄.出于這個原因,我會經常使用 /tmp
:
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
:
指定要寫入的路徑,如下所示:
Specify the path you want to write to as in:
INTO OUTFILE '/tmp/mydata.csv'
請注意,MySQL 會將文件寫入 MySQL 服務器,而不是您的客戶端計算機上.因此遠程連接將在遠程服務器上創建輸出文件.另請參閱SELECT INTO OUTFILE local ?了解更多詳情和解決方法.
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.
關于在運行 systemd
的 Linux 系統上寫入 /tmp
的注意事項:
最初發布此內容幾年后,我發現自己無法通過
Some years after originally posting this, I found myself unable to locate a file written to /tmp
via
...INTO OUTFILE '/tmp/outfile.csv'
在運行 Fedora Linux 和 systemd
的 MariaDB 5.5 服務器上.不是將文件直接寫入指定的 /tmp/outfile.csv
,而是在 /tmp
中的 systemd 目錄下創建該目錄和文件:
on a MariaDB 5.5 server running Fedora Linux with systemd
. Instead of writing the file directly to /tmp/outfile.csv
as specified, that directory and file were created beneath a systemd directory in /tmp
:
/tmp/systemd-mariadb.service-XXXXXXX/tmp/outfile.csv
雖然文件 outfile.csv
本身和 tmp/
子目錄都是可寫的,但 systemd 服務目錄本身有 700 個權限并且是 root 擁有的,需要 sudo
訪問權限以檢索其中的文件.
While the file outfile.csv
itself and the tmp/
subdirectory were both created world-writable, the systemd service directory itself has 700 permissions and is root-owned, requiring sudo
access to retrieve the file within it.
不是將 MariaDB 中的絕對路徑指定為 /tmp/outfile.csv
并將其相對指定為 outfile.csv
,而是按預期將文件寫入 MariaDB 的數據中當前所選數據庫的目錄.
Rather than specifying the absolute path in MariaDB as /tmp/outfile.csv
and specifying it relatively as outfile.csv
, the file was written as expected into MariaDB's data directory for the currently selected database.
這篇關于在 MySQL 中找不到 outfile 創建的文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!