2012-02-22 89 views
-1

我試圖執行SELECT INTO OUTFILE,我有以下錯誤ERROR權限使用SELECT INTO FILE ...在MySQL

我的要求:

SELECT * INTO OUTFILE '/local/home/datawords/upload/inscrit_newsletter_us.csv' 
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
LINES TERMINATED BY '\n' 
FROM newsletter_us; 

錯誤:

ERROR 1 (HY000): Can't create/write to file '/local/home/datawords/upload/exports/inscrit_newsletter_us.csv' (Errcode: 2)

exports目錄的權限設置爲0777.

+0

我敢打賭,你有'AppArmour'或'SELinux'運行。嘗試導出到MySQL數據目錄 - 如果這有效,這應該是證明。 – 2012-02-22 10:38:57

+0

研究努力失敗 – 2012-02-22 11:35:42

回答

3

您可以在如果有root權限的/ tmp文件夾

對於離select * into OUTFILE /tmp/inscrit_newsletter_us.csv

如果你不擁有的/ tmp文件夾根目錄權限手段,請按照下面的步驟

sudo chown root:root /tmp 
sudo chmod 1777 /tmp 
sudo /etc/init.d/mysqld restart 
+0

謝謝。文件已創建。我無法在grapical模式下通過winscp查看它! – Mamadou 2012-02-22 13:32:53

0

the documentation

The FILE privilege gives you permission to read and write files on the server host using the LOAD DATA INFILE and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function. A user who has the FILE privilege can read any file on the server host that is either world-readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.) The FILE privilege also enables the user to create new files in any directory where the MySQL server has write access. As a security measure, the server will not overwrite existing files.

確保您的用戶具有該特權。

然後檢查目標目錄權限是否符合上述要求。