LOAD DATA LOCAL INFILE中收到错误消息

时间:2012-06-11 09:39:07

标签: php mysql load-data-infile

我有这个错误:

Error message is :: "Error occured during query execution: (LOAD DATA LOCAL INFILE '/tmp/3sch.jofcial.txtgymCN5' REPLACE INTO TABLE `prod_sch` FIELDS TERMINATED BY ',' IGNORE 1 LINES (No_ ,Model_Code,Model_Name ,Lot_No_ ,Start_Seq_No_ ,Quantity ,Lot_Quantity ,Line_Code ,Line_Name ,@var10, Shift_No1,@var12,Shift_No2,@var14,Production_Mngm_Type,Model_Group,Model_Category,Actual_Results,MPS_Mngm_Code, Production_Mngm_Code,Comment) SET Production_Start_Date=STR_TO_DATE(@var10,'%m/%d/%Y'), Production_Finish_Date=STR_TO_DATE(@var12,'%m/%d/%Y'), Due_date=STR_TO_DATE(@var14,'%m/%d/%Y')): The used command is not allowed with this MySQL version";

尝试此语法后:

$temp_file = tempnam(sys_get_temp_dir(), '3sch.jofcial.txt');  // make temporary file name
$fp = fopen($temp_file, "wb");          // open temprary file
if (!$fp) die(_ERROR14);
fwrite($fp, $httpfile);                         // copy to temporary file from schedule file
fclose($fp);
chmod($temp_file, 0644);                        // file mode change for read only

$sql="TRUNCATE TABLE `prod_sch`";
$res=mysql_query($sql) ;//or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL $
$sql="LOAD DATA LOCAL INFILE '".$temp_file."' REPLACE INTO TABLE `prod_sch` FIELDS TERMINATED BY ',' IGNORE 1 LINES "; // FIELDS ENCLOSED BY '\"'$
$sql.="(No_ ,Model_Code,Model_Name ,Lot_No_ ,Start_Seq_No_ ,Quantity ,Lot_Quantity ,Line_Code ,Line_Name ,@var10, ";
$sql.="Shift_No1,@var12,Shift_No2,@var14,Production_Mngm_Type,Model_Group,Model_Category,Actual_Results,MPS_Mngm_Code, ";
$sql.="Production_Mngm_Code,Comment) ";
$sql.="SET Production_Start_Date=STR_TO_DATE(@var10,'%m/%d/%Y'), ";
$sql.="Production_Finish_Date=STR_TO_DATE(@var12,'%m/%d/%Y'), ";
$sql.="Due_date=STR_TO_DATE(@var14,'%m/%d/%Y')";

$res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL and$
unlink($temp_file);

将备份文件还原到新服务器后会发生此错误。从错误消息中我可以看到已经创建了临时文件。


修改

我试过了:

mysql --load-infile -u root -p pwd DBname

然后尝试将上面的查询放在>mysql内,此查询可以正常工作。 但是,为什么如果我使用PHP它不会?

尝试编辑/etc/mysql/my.cnf: add local-infile = 1 仍然无法工作。 这是php page

2 个答案:

答案 0 :(得分:7)

问题已解决

只需改变:

$dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());

进入:

$dbc=mysql_connect(_SRV, _ACCID, _PWD,false,128) or die(_ERROR15.": ".mysql_error());

Tadaaa ......所有错误都消失了!!

答案 1 :(得分:0)

来自here

  

如果在服务器或客户端中禁用了LOAD DATA LOCAL,则尝试发出此类语句的客户端会收到以下错误消息:

     

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