MySql Docker /docker-entrypoint-initdb.d wrong Encoding
Problem Description:
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.
Solution – 1
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