hkl: CSV -> mySQL

Beitrag lesen

Hallo !

hallo leute,

ich soll die daten von einer csv-datei in mySQL importieren.Ich benutze die folgende Anweisung :

LOAD DATA
        INFILE 'C:/Documents and Settings/kondeant/Desktop/rechnung.asc'
        REPLACE
        INTO TABLE mnet
        FIELDS
                TERMINATED BY ';'
                ENCLOSED BY '"'
        LINES
                 STARTING BY '"'
           TERMINATED BY '\n'

IGNORE 1 LINES

das problem liegt bei "IGNORE 1 LINES". wenn ich die zeile zu der anweisung dazufüge, bekomme ich in die Tabelle nur NULL-werte. wenn ich die ignore 1 lines weglasse, funktioniert alles,aber die spaltennamen von der csv-datei werden auch in die tabelle eingetragen, was ich nicht möchte.

was mache ich falsch?

Die Doku laesst folgendes vermuten :

Der PK steht wohl nicht in der INFILE, oder ?

Wenn der nicht da ist, und Du keine column list angibst, kann ja aus Sicht von MySQL die erste Zeile keinen gueltigen Header enthalten, da die Reihenfolge der columns ( wegen Fehlens des PK ) nicht stimmt.

"By default, when no column list is provided at the end of the LOAD DATA INFILE statement, input lines are expected to contain a field for each table column. If you want to load only some of a table's columns, specify a column list:"

  
LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata (col1,col2,...);  

"You must also specify a column list if the order of the fields in the input file differs from the order of the columns in the table. Otherwise, MySQL cannot tell how to match input fields with table columns."

Oder ist sonst die Reihenfolge der Felder zwischen (csv, sql) verschieden ?

--
Aus dem Perl Styleguide:
"Choose mnemonic identifiers. If you can't remember what mnemonic means, you've got a problem."