简体   繁体   中英

MySQL LOAD DATA LOCAL INFILE intermittently working

OS: Ubuntu 12.04.1 LTS MySQL Version: 5.5.28-0ubuntu0.12.04.2

When I try to run a LOAD DATA LOCAL INFILE I am getting error 1148 (The used command is not allowed with this MySQL version) - but only under the following circumstances

  • When the command is run via a PHP wget cron job (fails most times, works around every 1 in 4 times)
  • When the command is run via a PHP file in a browser session (fails twice, then usually works on the third time)

I'm seeing that if the script runs OK, and an effort is made to run it very soon after, it works fine - but waiting 5+ minutes after running it, it begins failing again, until I refresh it enough times to get it to run again. I need to run it successfully every time from cron.

I have added local-infile (not local-infile=1) under the [mysqld], [mysql] and [client] entries in my.conf, then restarted the server, to no avail. I have also tried entering loose-local-infile=1 under [client], but no joy.

The database folder was moved to a different location (/media/Data/mysql_data) and is owned by root.

The import file is downloaded to the local box with the permissions 0644.

Here is the command that's being run:

LOAD DATA LOCAL INFILE
            "/var/www/'.$import_dir.$table.'.csv"
            INTO TABLE _PREP_'.$table.'
            FIELDS TERMINATED BY ","
            OPTIONALLY ENCLOSED BY "\""

..$import_dir and $table being the path and name of the import file.

Has anyone else seen this before? Are there any logs I can view to see why it's failing? How come it's only intermittently failing?

It's all a bit weird. For the record, this is a new box, and the script has always behaved like this.

All help appreciated. -PaulG

Adding additional flag 128 to mysql_connect solves the problem for me. Check this for details mysql_connect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM