W
W
weranda2017-09-08 11:05:13
PHP
weranda, 2017-09-08 11:05:13

What is the algorithm for importing CSV into the database?

Greetings

There is a table in the database with the fields: id, name, age
There is a CSV file with the fields: id, name, age, gender I

import CSV into the database and the gender field is skipped, does not appear in the database - is it supposed to be, is this normal behavior? If there are fields in the CSV that match the names of the fields in the database, then only those that match will be imported, and the rest will be ignored - right?

It's just that there is a CSV file and the reluctance to delete several columns from it when importing.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey, 2017-09-09
@andrshpa

LOAD DATA INFILE '/status2_50m.csv'
INTO TABLE compression_test.accounts_status50m
FIELDS TERMINATED BY ';' ESCAPED BY '\\'
LINES STARTING BY '' TERMINATED BY '\n'
IGNORE 1 LINES
(@col1,@col2,@col3) set [email protected],[email protected],[email protected];

I think it’s a completely understandable example, adding this command will help in your situation
(@col1,@col2,@col3) set [email protected],[email protected],[email protected];

A
Alexey Alekseev, 2017-09-08
@greenkaktusx

A new field should not be added to the database during normal file import. First, bring the database structure to the desired form, and then load the data from the file.

A
Aidar, 2017-11-09
@Aderus

Так можно же галочку поставить,что первая строка в CSV это и есть поля и все. Они все должны добавится

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question