instrução mysql no script de shell bash não funciona / erro de sintaxe

1

espero que alguém possa me ajudar! Eu não sei o que há de errado com este script (Bash / Ubuntu 12.04 / Mysql / XAMPP 1.8.3). Tente ler um arquivo de entrada com uma lista de nomes de arquivos csv (449-R11, 449-R12 ..) para fazer algumas declarações sql ....

    #!/bin/bash

     OUTPath="/home/bono/RD/BV-OUT/tmp/distinct_"
     OUTPath1="/home/bono/RD/BV-OUT/tmp/load_"
     INPath="/home/bono/RD/BV-OUT/"

     while read line do
     RD="$line"
     bv_out_distinct=$OUTPath$RD
     bv_out_load_new_bvs=$OUTPath1$RD
     RDDATEI=$INPath$RD

     ###MYSQLs:
     /opt/lampp/bin/mysql --local-infile --user=root RD << EOF 
     LOAD DATA LOCAL INFILE $RDDATEI 
       INTO TABLE bv_tmp_all FIELDS TERMINATED BY ';';
     SELECT * FROM bv_tmp_all GROUP BY BAN 
       INTO OUTFILE $bv_out_distinct FIELDS TERMINATED BY ';' ;
     LOAD DATA LOCAL INFILE $bv_out_distinct 
       INTO TABLE bv_tmp_distinct FIELDS TERMINATED BY ';';
     UPDATE bv, bv_tmp_distinct 
       SET bv.RD=bv_tmp_distinct.RD,bv.LEV21=bv_tmp_distinct.LEV21 
       WHERE bv.BAN=bv_tmp_distinct.BAN;
     SELECT * FROM bv_tmp_distinct 
       WHERE BAN NOT IN (SELECT BAN FROM bv) 
       INTO OUTFILE $bv_out_load_new_bvs FIELDS TERMINATED BY ';';
     LOAD DATA LOCAL INFILE $bv_out_load_new_bvs 
       INTO TABLE bv FIELDS TERMINATED BY ';';
     TRUNCATE TABLE bv_tmp_distinct;
     TRUNCATE TABLE bv_tmp_all;
     EOF
     ##### EOSQL
     done < /home/bono/RD/BV-OUT/allto468

Eu tentei diferentes versões :(, nada funcionou .... Eu recebo este mysql-output:

bono@bono-S3210SH:~/RD/procs$ ./load_RD_out_tmp

ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; 
  check the manual that corresponds to your MyS INTO TABLE bv_tmp_all FIEL' 
  at line 1 to use near '"LOAD DATA LOCAL INFILE /home/bono/RD/BV-OUT/449-R11
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; 
  check the manual that corresponds to your MyS INTO TABLE bv_tmp_all FIEL' 
  at line 1 to use near '"LOAD DATA LOCAL INFILE /home/bono/RD/BV-OUT/449-R12
    
por Bono 07.02.2014 / 14:35

1 resposta

1

Seus nomes de arquivos devem ser escapados com aspas - o MySQL os considera strings, portanto seu bloco do MySQL deve ser:

LOAD DATA LOCAL INFILE '$RDDATEI' 
  INTO TABLE bv_tmp_all FIELDS TERMINATED BY ';';
SELECT * FROM bv_tmp_all GROUP BY BAN 
  INTO OUTFILE '$bv_out_distinct' FIELDS TERMINATED BY ';';
LOAD DATA LOCAL INFILE '$bv_out_distinct'
  INTO TABLE bv_tmp_distinct FIELDS TERMINATED BY ';';
UPDATE bv, bv_tmp_distinct 
  SET bv.RD=bv_tmp_distinct.RD,bv.LEV21=bv_tmp_distinct.LEV21 
  WHERE bv.BAN=bv_tmp_distinct.BAN;
SELECT * FROM bv_tmp_distinct 
  WHERE BAN NOT IN (SELECT BAN FROM bv) 
  INTO OUTFILE '$bv_out_load_new_bvs' FIELDS TERMINATED BY ';';
LOAD DATA LOCAL INFILE '$bv_out_load_new_bvs' 
  INTO TABLE bv FIELDS TERMINATED BY ';';
TRUNCATE TABLE bv_tmp_distinct;
TRUNCATE TABLE bv_tmp_all;
    
por Rudu 07.02.2014 / 16:45