26

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?

Norbert Egger
  • 263
  • 1
  • 3
  • 6

3 Answers3

43

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
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
Fotis
  • 1,322
  • 16
  • 30
  • 2
    added the config needed also to complete the answer – Tarun Lalwani Sep 01 '17 at 16:59
  • 1
    @Norbert Egger There also is a section "Configuration without a cnf file" but I'm not sure how that would apply to docker-compose. Perhaps would be handy for manual runs – Fotis Sep 01 '17 at 16:59
  • Thank you, it now works! I had do cleanup my docker (images and container) then rebuild everything and it worked. – Norbert Egger Sep 01 '17 at 18:23
34

For new comers to this question, I was able to make it work by basically removing mysqld from command: mysqld ... like so:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8 --collation-server=utf8_general_ci
    restart: always
    environment:

This is the same way as in the documentation for the official MySQL image, under section ... via docker stack deploy or docker-compose.


As a sidenote, you almost never want utf8 encoding in MySQL; you need utf8mb4. See this Q&A for more: What is the difference between utf8mb4 and utf8 charsets in MySQL?

rath
  • 3,655
  • 1
  • 40
  • 53
  • this is probably the fastest and easiest solution. On my side I just needed the `--character-set-server=utf8 --collation-server=utf8_general_ci` without the `--default-authentication-plugin` – рüффп Jan 27 '22 at 09:34
0

Now that Mysql8's default collation is utf8mb4_0900_ai_ci

mysql>  SELECT @@character_set_database, @@collation_database;
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4                  | utf8mb4_0900_ai_ci   |
+--------------------------+----------------------+

We don't have to set character set and its collation.

xblymmx
  • 39
  • 2
  • 3