Importing CSV File into MySQL Docker Container

> docker exec -it craig bash  
> mysql -u root -p --local-infile 
> use craigslist;
> 
> LOAD DATA LOCAL INFILE 'C:/Users/hank/Desktop/craigs/data.csv' 
> INTO TABLE books_mags  
> FIELDS TERMINATED BY ',' 
> LINES TERMINATED BY '\n'
> IGNORE 1 ROWS;

I have a csv file on my desktop that I am looking to enter into a MySQL table. But i am having a rough time figuring out the file path errors.

ERROR 2 (HY000): File ‘C:/Users/hank/Desktop/craigs/data.csv’ not found (OS errno 2 – No such file or directory)

I keep getting this error.

I am using a windows 10 and a docker containter for mySQL.

How can I put my csv into MYSQL?

This Post Has One Comment

  1. No Fault

    Directory path C:/Users/hank/Desktop/craigs/data.csv is in your host system(Windows). File system of your docker will be entirely different unless you have mounted the volume. Two ways to access the file inside the container

    First approach

    You’ll have to mount the volume when you start the container

    docker run -d image_name -v “C:/Users/hank/Desktop/craigs/:/data”
    This is not always recommended.

    Second Approach

    Copy the file from your host machine to the container using docker cp

    See ‘docker cp –help’.

    Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
    docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

    Copy files/folders between a container and the local filesystem
    It is similar to copying files to remote server using scp command.

Leave a Reply