Parameterizing file name in MYSQL LOAD DATA INFILE

后端 未结 4 1532
别跟我提以往
别跟我提以往 2020-12-11 18:53

Is there a way to dynamically specify a file name in the LOAD DATA INFILE? Can it be parameterized like for instance (syntax may be incorrect) LOAD DATA INFILE \'$filename\'

4条回答
  •  误落风尘
    2020-12-11 19:05

    Or you can make a temporary copy of the file (BATCH example):

    LOAD_DATA.bat

    COPY %1 TempFileToLoad.csv
    mysql --user=myuser --password=mypass MyDatabase < ScriptLoadMyDatabase.sql
    DEL TempFileToLoad.csv
    

    the SQL (for info) :

    ScriptLoadMyDatabase.sql

    load data infile 'TempFileToLoad.csv' IGNORE
    into table tLoad
    FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"'
    lines terminated by '\r\n'
    IGNORE 1 LINES
    (@DateCrea, NomClient, PrenomClient, TypeMvt, @Montant, NumeroClient)
    set DateCrea = str_to_date(@DateCrea, '%Y-%m-%d'), Montant = (round(@Montant / 1000)*2) ;
    

    And finished to put a link to the BAT file in SendTo windows folder.

提交回复
热议问题