简体   繁体   中英

MySql Docker /docker-entrypoint-initdb.d wrong Encoding

I'm trying to set up a simple mysql container with initialised data by copying a schema file to the folder /docker-entrypoint-initdb.d . The script gets executed but it seems to me that the encoding is wrong, because certain characters like 'ß' and 'ö' are not recognised and are turning to ß , no matter which encoding i specify.

The dockerfile looks like this:

FROM mysql

COPY schema.sql /docker-entrypoint-initdb.d

the schema I'm trying to execute looks something like this:

CREATE TABLE `test`
(
    `Nr`                     int(10)    NOT NULL DEFAULT '0',
    `Test`                   varchar(50)         DEFAULT NULL,
    `Straße`                 varchar(30)         DEFAULT NULL,
    `Ü`                      varchar(40)         DEFAULT NULL,
    `Ö`                      varchar(40)         DEFAULT NULL
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

The script runs fine when I apply it manually, but breaks every special character if it is applied as the entrypoint script.

I've tried changing the default charset of the table to different charsets as well as changing the encoding of the schema file, but nothing seems to work.

Somehow fixed it the following way:

  • Create empty MySql DB in Docker
  • Manually run the sql schema against the container
  • create a database dump with mysqldump
  • use that dump inside my dockerfile and copy it to /docker-entrypoint-initdb.d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM