0

When using a SQL file placed inside /docker-entrypoint-initdb.d/ defining functions fails with the following error:

ERROR 1064 (42000) at line 6: 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

This is the content of the SQL file:

CREATE DATABASE alpha;
USE alpha;

SET GLOBAL log_bin_trust_function_creators = 1;

create function addit(a int, b int) returns int
begin
    return a+b;
end

The above code works perfectly well when I connect to the instance after creation and run it.

Is it not allowed to define functions in db init scripts? How do I get around this?

Defrefh
  • 1
  • 1
  • The simple way is a single like function, it doesn't need `begin` or `end` so they can be removed. For longer line functions the `mysql` client is used, so [use delimiter](https://stackoverflow.com/questions/10259504/delimiters-in-mysql). – danblack Jun 04 '22 at 23:11

0 Answers0