Why does a perfectly valid function definition in MySQL (creating perfectly well with a locally installed server or a remote cloud one) cause an “You have an error in your SQL syntax” error?
Is there something about Docker images of MySQL that completely cuts out function definition syntax out of SQL?
Specifically, what I have is almost comically simple. My Dockerfile:
FROM mysql:8 COPY db_init.sql /docker-entrypoint-initdb.d/db_init.sql EXPOSE 3306
The initial db_init.sql file that works (without the function):
CREATE DATABASE alpha; USE alpha; create table status ( id int auto_increment primary key, description varchar(1000) not null );
The build & run commands:
docker build -t aaa . docker run -e MYSQL_ROOT_PASSWORD=aaa123 -p 3306:3306 aaa
After running the above everything works, I can connect to the db with DataGrip and see the status table in it.
However, when I add a MySQL valid function definition to the db_init.sql file:
CREATE DATABASE alpha; USE alpha; create table status ( id int auto_increment primary key, description varchar(1000) not null ); create function addit(a int, b int) returns int begin return a+b; end
It fails initialisation of the database container with the following communication:
ERROR 1064 (42000) at line 11: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
Line 11 corresponds to the “create function…” line in the db_init.sql file.
The very same code works flawlessly on a remote MySQL server, including executing function after creation:
What am I missing?