Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

php - Error 1148 MySQL The used command is not allowed with this MySQL version

I am using MySQL LOAD DATA LOCAL INFILE command and I get this error:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1148 The used 
command is not allowed with this MySQL version: LOAD DATA LOCAL INFILE 
'/tmp/phpI0ox54' INTO TABLE `dev_tmp` FIELDS TERMINATED BY ',' ENCLOSED 
BY '"' LINES TERMINATED BY '
' IGNORE 1 LINES; Array ( ) in 
dc_real_estate_form_submit() (line 147 of /PATH/TO/PHP/SCRIPT).

What setting can we change to allow LOAD DATA LOCAL infile?

Here is the Drupal 7 code we are using:

$sql = "LOAD DATA LOCAL INFILE '".$file."'
    INTO TABLE `dev_tmp`
    FIELDS
        TERMINATED BY ','
        ENCLOSED BY '"'
    LINES
    TERMINATED BY '\r\n'
    IGNORE 1 LINES";

db_query($sql);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Loading a local file in MySQL is a security hazard and is off by default, you want to leave it off if you can. When it is not permitted you get this error:

ERROR 1148 (42000): The used command is not allowed with this MySQL version

Solutions:

  1. Use --local-infile=1 argument on the mysql commandline:

    When you start MySQL on the terminal, include --local-infile=1 argument, Something like this:

    mysql --local-infile=1 -uroot -p
    
    mysql>LOAD DATA LOCAL INFILE '/tmp/foo.txt' INTO TABLE foo 
    COLUMNS TERMINATED BY '';
    

    Then the command is permitted:

    Query OK, 3 rows affected (0.00 sec)
    Records: 3  Deleted: 0  Skipped: 0  Warnings: 0
    
  2. Or send the parameter into the mysql daemon:

    mysqld --local-infile=1
    
  3. Or set it in the my.cnf file (This is a security risk):

    Find your mysql my.cnf file and edit it as root.

    Add the local-infile line under the mysqld and mysql designators:

    [mysqld]
    local-infile 
    
    [mysql]
    local-infile 
    

    Save the file, restart mysql. Try it again.

More info can be found here: http://dev.mysql.com/doc/refman/5.1/en/load-data-local.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...