csvmariadbraspberry-pi2

How do I load CSVs into tables in MariaDB running on a Raspberry Pi2?


I've installed MariaDB on my Pi2, which is connected to my network. I can access the Pi directly, through ssh or even VNC. I can also connect to it using MySQL Workbench.

I have CSVs (Fantasy Football stats) I'm trying like to load into a table in a database, both of which I've already created.

CREATE DATABASE stats;
USE stats;
CREATE TABLE ff2020(
    id INT NOT NULL AUTO_INCREMENT,
    PlayerName VARCHAR(255) NOT NULL,
    Team VARCHAR(255) NOT NULL,
    Position VARCHAR(255) NOT NULL,
    Age INTEGER,
    GamesPlayed INTEGER,
    GamesStarted INTEGER,
    Targets INTEGER,
    Receptions INTEGER,
    PassingYds INTEGER,
    PassingTDs INTEGER,
    PassingAtt INTEGER,
    RushingYds INTEGER,
    RushingTDs INTEGER,
    RushingAtt INTEGER,
    ReceivingYds INTEGER,
    ReceivingTDs INTEGER,
    FantasyPoints INTEGER,
    Interceptions INTEGER,
    Fumbles INTEGER,
    FumblesLost INTEGER,
    PRIMARY KEY (id)
);

I used WinSCP to transfer the files containing the CSVs from my computer to the RPi, and orginally put the file containing the CSVs right on the desktop.

USE stats;
LOAD DATA INFILE '/home/pi/Desktop/CSVs for stats/data-master/yearly/2020.csv'
INTO TABLE ff2020
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '/n'
IGNORE 1 ROWS;

In response, I get the message: Error Code: 1045. Access denied for user 'marine'@'localhost' (using password: YES)

The user marine has all privileges, but the same thing happens using root. I've seen other posts that mention changing:

LOAD DATA INFILE...

to

LOAD DATA LOCAL INFILE...

When I try that, I get the message:Error Code: 2068. LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.

I also saw someone talk about reversing all the slashes in the file path, but when I tried I didn't get any different results.

So, I'm assuming there's a problem where MariaDB can't see or access other files on the pi and I don't know how to remedy this. Do I need to do something more elaborate, like enable remote access to MariaDB, even though everything is on one device?

Thanks.


Solution

  • pass --local-infile when you login

    mysql -u[username] -p[password] --local-infile
    

    then specifying LOAD DATA LOCAL INFILE... should do the trick