Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup mysql with utf-8 using docker compose?

I am trying to get my mysql image running with utf-8 encoding. My docker-compose file looks like:

version: '2'
services:
  db:
    container_name: zoho-grabber-db-development
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=topsecret
      - MYSQL_DATABASE=development
      - MYSQL_USER=devuser
      - MYSQL_PASSWORD=secure
    ports:
      - "3306:3306"
    command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci

When i run it, it says

$ docker-compose -f docker-compose.development.yml up
Removing zoho-grabber-db-development
Recreating 1b341fd7916e_1b341fd7916e_zoho-grabber-db-development

ERROR: for db  Cannot start service db: oci runtime error: container_linux.go:247: starting container process caused "exec: \"mysqld\": executable file not found in $PATH"
ERROR: Encountered errors while bringing up the project.

Why is mysqld not found? And how to achieve my goal?

like image 982
Norbert Egger Avatar asked Sep 05 '25 03:09

Norbert Egger


1 Answers

When using command in docker-compose.yml it overrides the default command and entrypoint as described in the docker-compose documentation. In order for you to achieve your goal, I suggest that you mount a my.cnf as a volume as described in the docker image's readme under section "Using a custom MySQL configuration file".

So remove command from your docker-compose and add volumes eg.

...
volumes:
  - mycustom.cnf:/etc/mysql/conf.d/custom.cnf
...

and the container will include your custom configuration as the server's configuration

Edit-1

Below is the custom config the you need

mycustom.cnf

[mysqld]
character-set-server = utf8
collation-server = utf8_unicode_ci
skip-character-set-client-handshake
like image 158
Fotis Avatar answered Sep 08 '25 01:09

Fotis