简体   繁体   中英

mysql LOAD DATA INFILE generates dummy data

@OpenCart 1.5.5 I'm trying to export some rows from certain tables from source DB using this command, for example:

mysql_query("
  SELECT `group`,`key`,`value`,`serialized` 
  INTO OUTFILE '".$outputDir ."/".$dbPrefix ."setting.csv' FIELDS TERMINATED BY ',' 
  OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM `".$dbPrefix."setting` 
  WHERE `group` = 'banner' OR `group` = 'bestseller' 
  OR `group` = 'carousel' OR ` .....
")

After I delete these tables I try to import this file to the target DB using the following command:

mysql_query("
  LOAD DATA INFILE '". $outputDir ."/". $dbPrefix ."setting.csv'   
  INTO TABLE `".$tDbPrefix."setting` FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED 
  BY '\"' LINES TERMINATED BY '\n'
")

The problem is it generates dummy data with weird formatting; for example:

 <li class="contact-2 cle"... 

I use UTF-8 encoding and databases are identical.

i found out the problem ... i had to define the tables i'm importing the right syntax is

mysql_query("LOAD DATA INFILE '". $outputDir ."/". $dbPrefix ."setting.csv'   INTO TABLE `".$tDbPrefix."setting` FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' (`group`,`key`,`value`)");

thats why it used to generate dummy data and by defining the imported tables it works all fine

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