2012-05-24 45 views
10

我有一個PHP腳本,它調用MySQL的LOAD DATA INFILE來從CSV文件加載數據。然而,生產服務器上,我結束了以下錯誤:LOAD DATA LOCAL INFILE給出錯誤使用的命令不允許使用此MySQL版本

Access denied for user ... (using password: yes)

作爲一個快速的解決辦法,我改變了命令LOAD DATA LOCAL INFILE哪些工作。然而,同樣的命令客戶端的服務器上與此消息失敗:

The used command is not allowed with this MySQL version

我認爲這事做與服務器變量:local_infile = off描述here

請建議一種解決方法,不涉及更改服務器設置。請注意,安裝在同一服務器上的phpMyAdmin實用程序似乎接受CSV文件,但我不確定它是否使用LOAD DATA (LOCAL) INFILE

+0

它不是該命令是您正在使用的用戶的權限。 – jcho360

+0

同一個用戶可以運行'INSERT'查詢,但不能運行'LOAD DATA INFILE'(訪問被拒絕)或'LOAD DATA LOCAL INFILE'(使用的命令不被允許)。 –

回答

39

遇到同樣的問題,因爲根把我一會兒

可能是與編譯

設置爲測試登錄服務器設置到控制檯使用相同的用戶和嘗試的問題您的加載數據命令

,如果你得到了同樣的錯誤,請嘗試關閉控制檯和運行

mysql -u USER -p --local-infile=1 DATABASE 
與配置選項

現在嘗試運行負荷數據命令再次

,如果它工作,然後你將需要重新啓動命令行選項或mysqld的重新安裝

引用(引用是5.0,但對於工作我用5.5):

http://dev.mysql.com/doc/refman/5.0/en/load-data-local.html

http://dev.mysql.com/doc/refman/5.0/en/mysql-command-options.html#option_mysql_local-infile

+3

「mysql -u USER -p --local-infile = 1 DATABASE」。這個命令完成了所有的操作。謝謝。 –

+0

你的歡迎,雖然它更清潔,其他人通過upvote – Alvin

+0

給予感謝非常有用的答案,自己遇到這個問題 – Rickyfox

0

看看這個權限列表,你可以分別添加它們,IE。您可以插入,但不能更新,也可以刪除,但無法選擇,等等

ALL [PRIVILEGES] Grant all privileges at specified access level except GRANT OPTION 
ALTER Enable use of ALTER TABLE 
ALTER ROUTINE Enable stored routines to be altered or dropped 
CREATE Enable database and table creation 
CREATE ROUTINE Enable stored routine creation 
CREATE TEMPORARY TABLES  Enable use of CREATE TEMPORARY TABLE 
CREATE USER  Enable use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES 
CREATE VIEW  Enable views to be created or altered 
DELETE Enable use of DELETE 
DROP Enable databases, tables, and views to be dropped 
EVENT Enable use of events for the Event Scheduler 
EXECUTE  Enable the user to execute stored routines 
FILE Enable the user to cause the server to read or write files 
GRANT OPTION Enable privileges to be granted to or removed from other accounts 
INDEX Enable indexes to be created or dropped 
INSERT Enable use of INSERT 
LOCK TABLES  Enable use of LOCK TABLES on tables for which you have the SELECT privilege 
PROCESS  Enable the user to see all processes with SHOW PROCESSLIST 
REFERENCES Not implemented 
RELOAD Enable use of FLUSH operations 
REPLICATION CLIENT Enable the user to ask where master or slave servers are 
REPLICATION SLAVE Enable replication slaves to read binary log events from the master 
SELECT Enable use of SELECT 
SHOW DATABASES Enable SHOW DATABASES to show all databases 
SHOW VIEW Enable use of SHOW CREATE VIEW 
SHUTDOWN Enable use of mysqladmin shutdown 
SUPER Enable use of other administrative operations such as CHANGE MASTER TO, KILL, PURGE BINARY LOGS, SET GLOBAL, and mysqladmin debug command 
TRIGGER  Enable trigger operations 
UPDATE Enable use of UPDATE 
USAGE Synonym for 「no privileges」 

我認爲你必須permision選擇,刪除,插入,更新,但沒有做其他的東西,

使用這個命令:

SHOW GRANTS 

,他會告訴你,你是什麼能到,在我的情況。

jcho360> show grants; 
+-------------------------------------------------------+ 
| Grants for [email protected]       | 
+-------------------------------------------------------+ 
| GRANT ALL PRIVILEGES ON *.* TO 'jbolivar'@'localhost' | 
+-------------------------------------------------------+ 
1 row in set (0.00 sec)