mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Issue with entrypoint with DELIMITER?

Open nicon89 opened this issue 3 years ago • 4 comments

I have an issue with SQL entrypoint, which runs without any issues when imported manually.

Error:

database    | 2021-03-08 16:07:08+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/0.sql
database    | ERROR 1064 (42000) at line 1: 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 'DELIMITER $$
database    | /*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `test` */$$' at line 3

Example SQL file:

/* Trigger structure for table `test` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `test` */$$
Image:
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 d54bd1054823        9 days ago          449MB

Docker version:
19.03.8

Can someone help me with this, please?

nicon89 avatar Mar 08 '21 16:03 nicon89

The entrypoint script just passes the .sql file contents to the mysql client, so seems it could be related to this old bug: https://bugs.mysql.com/bug.php?id=11523.

https://github.com/docker-library/mysql/blob/d9fecf6b0bd4f4072a6e1e590ec811167aab2fab/template/docker-entrypoint.sh#L72 https://github.com/docker-library/mysql/blob/d9fecf6b0bd4f4072a6e1e590ec811167aab2fab/template/docker-entrypoint.sh#L217

\d works though.

root@f7fd9a6e9667:/# mysql -uroot -p12345 -hlocalhost --comments <<'EOF'
/* Trigger structure for table `test` */

\d $$

SELECT * FROM mysql.user $$
EOF
mysql: [Warning] Using a password on the command line interface can be insecure.
... [mysql.user table]

yosifkit avatar Mar 09 '21 01:03 yosifkit

I'm having the same issue. It works fine up until 8.0.21 but is broken with 8.0.22 and 8.0.23. Just given the dates of the commits involved I think maybe the issue is the addition of the "--comments" option here but I don't know how to test that theory.

tombriggsallego avatar Apr 05 '21 16:04 tombriggsallego

I can confirm that this is due to the --comments flag. Since the comment stripping feature of the mysql client is deprecated we probably need to get used to making things work with --comments enabled though, unfortunately. To do that I used a bit of Perl from here to remove all multi-line comments from our .sql files before pushing them into the docker container; after that everything works fine.

tombriggsallego avatar Apr 26 '22 21:04 tombriggsallego

@ltangvald :see_no_evil: :heart: :pray:

Following up on https://github.com/docker-library/mysql/issues/718 and https://github.com/docker-library/mysql/pull/728, it sounds like the deprecation of --comments is probably the reason I was looking for in https://github.com/docker-library/mysql/issues/718#issuecomment-704478430 for why we shouldn't enable it :sweat_smile:

So, I guess we're looking for alternate ways to fix https://github.com/docker-library/mysql/issues/718 so we can revert https://github.com/docker-library/mysql/pull/728 again? :grimacing:

tianon avatar Jun 10 '22 21:06 tianon