5

I'm running a MySQL docker container (latest - 8.0) with the custom configuration file containing:

======================================
[client]

default-character-set=utf8mb4

[mysqld]
collation_server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character_set_server = utf8mb4

[mysql]
default-character-set=utf8mb4
======================================

Executing inside MySQL console:

show variables like "%coll%";

produces this:

+-------------------------------+--------------------+
| Variable_name                 | Value              |
+-------------------------------+--------------------+
| collation_connection          | utf8mb4_0900_ai_ci |
| collation_database            | utf8mb4_unicode_ci |
| collation_server              | utf8mb4_unicode_ci |
| default_collation_for_utf8mb4 | utf8mb4_0900_ai_ci |
+-------------------------------+--------------------+

Executing inside MySQL console:

show variables like "%char%";

produces this:

+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8                           |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+

BUT when I go the MySQL console with:

docker exec -it mysql1 mysql -uroot -p********* 

I can't use cyrillic (russian) characters. When I switch to Russian locale and try to type anything, the console just ignores keypresses, nothing is displayed on the screen. But when I switch to English locale, everything starts working again.

What can I do to solve this problem?

PS: I AM able to interact with the database via DataGrip and enter Russian characters for table names, fields and records. I'm just completely unable to use Russian characters when I'm inside the MySQL console inside the docker container.

PPS: MySQL is running from an official Docker image on MacOS Mojave and I'm using iTerm 3.2.6. Character encoding in iTerm is set to "Unicode (UTF-8)"

5
  • Windows? *nix? What charset is established for the terminal / cmd program?
    – Rick James
    Commented Dec 28, 2018 at 20:49
  • @RickJames Just amended the question with more details.
    – ruslaniv
    Commented Dec 29, 2018 at 5:54
  • init-connect is ignored by root, but that won't explain the problem. Were those SHOWs done via docker's MySQL console?
    – Rick James
    Commented Dec 29, 2018 at 6:02
  • @RickJames Yes. I first login to docker MySQL container via docker exec -it mysql1 mysql and then execute the show commands.
    – ruslaniv
    Commented Dec 29, 2018 at 6:45
  • I start to think this is a Docker problem now, I just finished installing MySQL in a RedHat VM and on a physical computer running RedHat and in both instances I did not even have to specify the encoding for MySQL, it just supports Cyrillic characters out of the box without any problems whether I login via SSH from Mac or work directly in RedHat terminal.
    – ruslaniv
    Commented Dec 29, 2018 at 6:54

3 Answers 3

7

As it turns out this was indeed a Docker problem rather than MySQL.

Vanilla MySQL image is built on Debian 9 and by default it lacks UTF-8 support. So I had to follow these steps:

  1. Login into Docker container with docker exec -it mysql1 bash and run apt-get update
  2. Then run apt-get install vim apt-get install locales
  3. Run dpkg-reconfigure locales and select 376 for ru_RU.UTF-8
  4. Open ~/.bashrc and add

export LANG=ru_RU.utf8

export LANGUAGE=ru_RU.utf8

export LC_ALL=ru_RU.utf8

  1. Exit the shell and restart the container

Now I can use Russian characters inside the MySQL docker console.

PS: I guess a cleaner and more "Dockeresque" solution would be to run these commands from a Dockerfile. If anybody could provide an answer with a dockerfile example, I'd be happy to accept it.

2
  • 1
    Not sure if this would help, but just FYI, I started the container with docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci, which did not have the locales package, but still that solved my non-latin character display problem.
    – wlnirvana
    Commented Mar 28, 2020 at 9:17
  • @wlnirvana I'll give this a try, although you're using 5.7 and I need to use 8.X
    – ruslaniv
    Commented Mar 28, 2020 at 9:53
1

Run the Docker container with a:

-e LANG=C.UTF-8

Or update your Dockerfile:

ENV LANG C.UTF-8

0

I have the exact same problem for typing french accented character. Using the answer from ruslaniv, here is a Dockerfile allowing you to correct this problem:

FROM mariadb:10.3.23
RUN apt update && \
    apt install locales
RUN locale-gen --purge "en_US.UTF-8" && \
    dpkg-reconfigure --frontend noninteractive locales && \
    echo export LC_ALL=en_US.utf8 >>  ~/.bashrc

Note that the problem is the same for the MariaDB Docker image, and that you only have to specify any valid UTF-8 locale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.