P粉2682849302023-08-29 11:03:12
DELIMITER is a client-only statement, the server does not support it, hence the error. Solution - delete it.
Here is a question with a very good answer that explains what DELIMITER is and why it is needed.
In short - when you are working with a client you need a way to indicate to it "this is not an immediately executed statement, this is still just a line in the stored procedure that you will send to the server" - so You tell (the client) "DELIMITER between statements is $$ temporarily". The server doesn't need/care about this - it knows that everything between CREATE PROCEDURE, BEGIN, END
is a connected statement, a block.
When you connect to the database via API (pymysql), compared to interactive clients (shell, heidisql, etc.) - you send the SP as a chunk and there is no way to run its statements one by one, so DELIMITER is not needed , the server does not support the command and an error will be generated. Delete it.