A Y
A Y

Reputation: 139

Mysql: Change charset to UTF-8

I am trying to set up Confluence with docker-mysql. I have followed all instructions I could find on the net and Confluence is still giving me the Your database must be configured to either use utf8 or utf8mb4 as the default character set.

Here's my docker-compose:

version: '3.3'
services:
  db:
    image: mysql:5.7
    volumes:
            - ./mycustom.cnf:/etc/mysql/conf.d/my.cnf
    restart: always
    command: --sql_mode=""
    environment:
      MYSQL_DATABASE: bachelorarbeit_database
      # So you don't have to use root, but you can if you like
      MYSQL_USER: horizon
      # You can use whatever password you like
      MYSQL_PASSWORD: 1P@ssw0rt123
      # Password for root access
      MYSQL_ROOT_PASSWORD: P@ssw0rt
      MYSQL_ROOT_USER: root
    ports:
      # <Port exposed> : < MySQL Port running inside container>
      - '3310:3306'

Here's the mycustom.cnf that's in the same directory as the docker-compose

[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_bin
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=2GB
transaction-isolation=READ-COMMITTED
binlog_format=row

Here's the my.cnf file

[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_bin
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=2GB
transaction-isolation=READ-COMMITTED
binlog_format=row

Upvotes: 1

Views: 4762

Answers (1)

antun
antun

Reputation: 2297

It seems that by default, when creating a MySQL database with docker-compose, it defaults to latin1.

You can override that by passing the following command in your db service:

command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0

I'm not sure what the --sql_mode="" is doing there is that just passing an argument to the default command? If so you'd probably add that to the list of arguments.

Once you've re-started your containers, you can login to the mysql one and running the following SQL to confirm it is now UTF-8:

mysql> SELECT @@character_set_database, @@collation_database;
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8                     | utf8_unicode_ci      |
+--------------------------+----------------------+
1 row in set (0.00 sec)

Upvotes: 5

Related Questions