MySQL: Set utf8mb4 in default

Build Docker Compose to test one production system.

That requires UTF8 database.

Because, in default, the Docker Image (https://hub.docker.com/_/mysql) is not utf8mb4.

Better to set the default-character-set on mysqld.cnf.


docker-compose.yml
volumes:
  - ./mysql/data:/var/lib/mysql
  - ./mysql/conf.d/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf


Edit the mysqld.cnf:
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci


More, as the data, "Error Code: 1292. Incorrect datetime value", set:
[mysqld]
 
[...]
 
sql-mode = "NO_ENGINE_SUBSTITUTION"



References

In MySQL, never use “utf8”. Use “utf8mb4”

Why better is  utf8mb4_unicode_ci
https://stackoverflow.com/a/51289054


Update