从Infobright上的脚本运行时加载DATA INFILE错误

时间:2012-09-19 04:20:35

标签: mysql shell

在infobright提示符下运行时,查询执行完全正常:

mysql> LOAD DATA INFILE '/tmp/test.agg' IGNORE INTO TABLE tb_message_content FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\'LINES TERMINATED BY '\n';
Query OK, 2 rows affected

但是,从shell脚本运行时,同一查询会出错:这是脚本解释查询的方式

mysql -u amr_ts_scripts -pamr_ts_scripts MVR4_ETL_DB -S /tmp/mysql-ib.sock -N -e 
$'LOAD DATA INFILE \'/tmp/test.agg\'
 IGNORE INTO TABLE tb_message_content \n      
 FIELDS TERMINATED BY \',\' \n             
 OPTIONALLY ENCLOSED BY \'"\' \n             
 ESCAPED BY \'\\\'\n      
 LINES TERMINATED BY \'\\n\';'

引用的错误是:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\'
      LINES TERMINATED BY ''' at line 4
PAGER set to stdout

有人能指出我面临的问题吗?

1 个答案:

答案 0 :(得分:0)

stmt="LOAD DATA INFILE '$1' IGNORE INTO TABLE $2 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\n';

脚本中的上述语句有效,因为需要ESCAPED BY'\\'来转义每个'\'。