How to import a csv file into MySQL?

2

I'm starting my studies in MySQL. I decided to install MariaDB 10.1.14 on CentOS. I want to create a database from a .csv file with approximately 166 million rows. I searched for tutorials on the internet, but it seems they all assume that the user knows something a priori about databases, which is not my case. Also, I'm finding the official MariaDB documentation a bit complicated, with few examples.

That said, suppose I have the test.csv file and its contents are as follows:

UF,ValorParcela,MêsCompetência
PE,185.00,01/2015
AM,147.00,01/2015
PR,232.00,01/2015
PE,310.00,01/2015
PB,463.00,01/2015
CE,182.00,01/2015
AL,112.00,01/2015
MG,112.00,01/2015
BA,112.00,01/2015

Suppose I want to import the contents of this test.csv into a database purse. So far, I've found that I need to do the following:

CREATE DATABASE bolsa;
USE bolsa;
LOAD DATA LOCAL INFILE teste.csv;
INTO TABLE bolsa
FIELDS TERMINATED by ','
LINES TERMINATED BY '\n';

Only this code is not correct. The error messages are not clear to me. I would appreciate it if anyone could give me a light on how to resolve this issue.

    
asked by anonymous 20.07.2016 / 20:46

1 answer

0

Try ignoring the first line and passing the full path of the csv file:

LOAD DATA INFILE 'c:/tmp/teste.csv';
INTO TABLE bolsa
FIELDS TERMINATED by ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

Source: link

    
20.07.2016 / 22:20