The blog about containerisation, virtual machines and useful shell snippets and findings

Use MySQL in docker with utf-8 encoding and utf8_general_ci

  • Use custom command to launch mysql container with right collation:
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
  • Alter existing database:
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

use

docker-compose exec db mysql -uuser -ppass database

to exec your queries in running container.