load data infile import not working and none of the other topics helped
-
11-06-2021 - |
Question
This is the table i want to import in:
create table if not exists Medici( m_id int unsigned AUTO_INCREMENT PRIMARY KEY, m_nume VARCHAR(50), m_prenume VARCHAR(50), Statut ENUM('primar', 'specialist'), Specialitate VARCHAR(50)
) ENGINE = InnoDB DEFAULT CHARSET = utf8;
And the CSV starts with:
- Nume,Prenume,Tip,Specialitate
- Bunica,Mihai-Daniel,primar,reumatologie
- Donca,Cornelia-Ana,primar,chirurgie
- Achiriloaie,Lorand-Levente,specialist,neurologie
The code I wrote is:
load data infile 'D:/xxxxxxxxxxxxx/xxxxxxx/xxxxxxxxxx/xxxxxx/xxxxxxxxxx/medici.txt' into table Medici character set utf8 fields terminated by ',' lines starting by 'Nume,Prenume,Tip,Specialitate\n' terminated by '\n' (m_nume,m_prenume,Statut,Specialitate);
Note: I changed terminated with \n, \r, \r\n, and i still get 1 row. Even with removing lines terminated by and it's not working.
Note: I pasted quickly and messed up a bit, there are 4 rows there. And ye the csv i assume it's formated correctly
Can't wait for advice, Thanks in advance.
more of the code here: Nume,Prenume,Tip,Specialitate Bunica,Mihai-Daniel,primar,reumatologie Donca,Cornelia-Ana,primar,chirurgie Achiriloaie,Lorand-Levente,specialist,neurologie Papuc,Raducu-Liviu,primar,homeopatie Cucuiu,Nutu,primar,ortopedie Buia,Tache,specialist,ginecologie Dragomanu,Mitrut,specialist,ecografie Ticu,Simona,specialist,psihiatrie Ene,Adrian-Stefan,specialist,pediatrie Copae,Toma,primar,neurologie Hotoi,Dragos Alin,specialist,pediatrie Ceafalau,Vincenţiu Mihail,primar,pediatrie Briceag,Anca Stefana,primar,imagistica Condrea,Nutu,primar,fizioterapie Cruceru,Ioana-Loredana,primar,dermatologie Soarece,Dan-Cristian,primar,o.r.l. Tatasel,Alexandru-Ovidiu,specialist,psihologie Sterian,Gologaneanu,primar,chirurgie Postelnicu,Habib,primar,chirurgie Silviu ,Adrian Ionut,primar,dermatologie Paius,Ioana,specialist,ortopedie Borza,Marius Florian,specialist,fizioterapie Tamas,Ciprian Costel,primar,chirurgie Ograzeanu,Cristina Alexandra,primar,endocrinologie Rildo,Alex,specialist,ecografie
In the csv these lines are merged ( one row to another ) For example: After reumatologie it starts with the name but when i paste the code you can see it's actually an \n Bunica,Mihai-Daniel,primar,reumatologieDonca,(.... here is 2nd row and so on)
Solution
Try this command:
load data local infile
'D:/xxxxxxxxxxxxx/xxxxxxx/xxxxxxxxxx/xxxxxx/xxxxxxxxxx/medici.txt'
into table Medici character set utf8 fields terminated by ','
lines terminated by '\n' IGNORE 1 LINES (m_nume,m_prenume,Statut,Specialitate);