Skip to content

Instantly share code, notes, and snippets.

@w0rldart
Last active December 23, 2024 20:49
Show Gist options
  • Save w0rldart/aa472db45c3817d937a1870a32f77820 to your computer and use it in GitHub Desktop.
Save w0rldart/aa472db45c3817d937a1870a32f77820 to your computer and use it in GitHub Desktop.
MariaDB docker-compose with UTF8 Collation
version: '3.1'
services:
db:
image: mariadb
restart: always
command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=example
- MYSQL_DATABASE=test
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testpassword
@Anonymous-except
Copy link

👍

@warmos9
Copy link

warmos9 commented Sep 24, 2022

thanks

@w0rldart
Copy link
Author

thanks

Hakuna Matata

@AndreyGer-hub
Copy link

AndreyGer-hub commented Nov 6, 2022

This doesn't work for me for any magic reason. My tables collations and collation of connection is still latin1_swedish_ci, although collation_server is utf8_unicode_ci. I solved it by setting this options to mysql config file directly (my.cnf).

my.cnf:

[mysqld]
init_connect=‘SET collation_connection = utf8_unicode_ci’
character-set-server = utf8
collation-server = utf8_unicode_ci

[client]
default-character-set = utf8

docker-compose.yml:

version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=example
      - MYSQL_DATABASE=test
      - MYSQL_USER=testuser
      - MYSQL_PASSWORD=testpassword
    volumes:
      - ./my.cnf:/etc/mysql/my.cnf

p.s. my.cnf is placed near docker-compose.yml in this example. You can put it in another folder, but you should change path in volumes part

@PerryRylance
Copy link

This didn't work for me sadly, first method just causes the container to fail with Can't create test file /opt/bitnami/mariadb/data/97647bac093c.lower-test. Second method has no effect.

I have a UTF-8 SQL dump that includes emojis.

@warmos9
Copy link

warmos9 commented Feb 12, 2024

Try using the image mariadb as described in gist. Bitnami could have some customization, which might be incompatible with example above

@gecube
Copy link

gecube commented Sep 2, 2024

does not work for me

2024-09-02 09:01:44+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:44+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:01:45+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:45+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:01:46+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:46+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:01:47+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:47+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:01:48+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:48+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:01:50+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:50+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:01:54+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:01:54+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:02:01+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:02:01+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found
2024-09-02 09:02:14+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started.
2024-09-02 09:02:14+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config
	command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect=SET NAMES UTF8; --innodb-flush-log-at-trx-commit=0 --verbose --help
	/usr/local/bin/docker-entrypoint.sh: line 105: mysqld: command not found

@phulstaert
Copy link

phulstaert commented Oct 18, 2024

the mariadb docker image doesn't use 'mysqld' as a startingpoint, but 'mariadbd'.
(the same is for the client, it isn't 'mysql', but 'mariadb')

appending command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci to the docker file won't work.
command: mariadbd --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci will work.

Better is to use the line below; it works both on mariadb and mysql.
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']

@SKJoy
Copy link

SKJoy commented Dec 23, 2024

This doesn't work for me for any magic reason. My tables collations and collation of connection is still latin1_swedish_ci, although collation_server is utf8_unicode_ci. I solved it by setting this options to mysql config file directly (my.cnf).

my.cnf:

[mysqld]
init_connect=‘SET collation_connection = utf8_unicode_ci’
character-set-server = utf8
collation-server = utf8_unicode_ci

[client]
default-character-set = utf8

docker-compose.yml:

version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=example
      - MYSQL_DATABASE=test
      - MYSQL_USER=testuser
      - MYSQL_PASSWORD=testpassword
    volumes:
      - ./my.cnf:/etc/mysql/my.cnf

p.s. my.cnf is placed near docker-compose.yml in this example. You can put it in another folder, but you should change path in volumes part

This worked for me too. Just a little note, you need to use SINGLE QUOTES around for the line init_connect=‘SET collation_connection = utf8_unicode_ci’. Thanks mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment