Issue
I am trying to build a mysql container using a docker file and an SQL file to create the tables but I keep getting this error in my terminal:> [3/3] RUN /docker-entrypoint-initdb.d/books.sql: #7 0.686 /docker-entrypoint-initdb.d/books.sql: line 1: syntax error near unexpected token
`('
'7 0.686 /docker-entrypoint-initdb.d/books.sql: line 1: ``CREATE TABLE "articulos" (`
where it says I have a "`" in from of CREATE and I don't why that's showing up.
here is my docker file
FROM mysql:latest
ENV MYSQL_DATABASE books
COPY ./sqlscript /docker-entrypoint-initdb.d/
RUN /docker-entrypoint-initdb.d/books.sql
and this is my SQL file
CREATE TABLE "articulos" (
"id" int NOT NULL AUTO_INCREMENT,
"titulo" text,
"contenido" text,
"fechacreacion" date DEFAULT NULL,
"categoria" text,
PRIMARY KEY ("id")
) ENGINE=InnoDB AUTO_INCREMENT=143 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Thank you in advance.
Solution
You could be facing two problems:
- Docker is trying to run your
.sql
file as if it was abash
script - And anyway, your MySQL server might not be running when building
Try removing your last Dockerfile line (RUN /docker-entrypoint-initdb.d/books.sql
).
It might work like you want it to since I presume that .sql
files placed in the /docker-entrypoint-initdb.d/
directory are executed on startup.
Answered By - Camille Louédoc Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.