MariaDB with Docker trying to load in an SQL file

223 views Asked by At

I'm currently trying to get some dummydata for my project. So I setup a docker file and I am trying to load in some data from a csv file. I'm not getting any error's just an empty database.

Docker:

version: "3.3"

services:
  maria-db:
    image: 'mariadb:latest'
    ports:
      - '3307:3306'
    environment:
      MYSQL_DATABASE: 'researchprojectdb'
      # So you don't have to use root, but you can if you like
      MYSQL_USER: 'user'
      # You can use whatever password you like
      MYSQL_PASSWORD: 'password'
      # Password for root access
      MYSQL_ROOT_PASSWORD: 'admin'
    volumes:
      - ./scripts/researchprojectdb.sql:/docker-entrypoint-initdb.d/1.sql
      - ./data:/var/lib/mysql-files

SQL Script:

CREATE TABLE ROLES (
    role_id int PRIMARY KEY,
    role varchar(20)
);

CREATE TABLE USERS (
    user_id int PRIMARY KEY,
    firstname varchar(83),
    lastname varchar(83),
    email varchar(83),
    password varchar(83)
    role_id int,
    foreign key (role_id) references roles(role_id)
);

INSERT INTO ROLES VALUES(1, 'student');
INSERT INTO USERS VALUES(1,'Jan', 'Met de pet', '[email protected]', 'depet', 1);
-- LOAD DATA LOCAL INFILE '/var/lib/mysql-files/rolesdata.csv' into TABLE ROLES FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 0 ROWS;
-- LOAD DATA LOCAL INFILE '/var/lib/mysql-files/usersdata.csv' into TABLE USERS FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 0 ROWS;

and then I use 2 .csv files with the following data:

Roles:

1   student
2   administrator
3   company

Userdata

1   Jan heas    [email protected] depet   1
0

There are 0 answers