Unable to use cyrillic characters in mysql docker console
Вопрос
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)"
Решение
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:
- Login into Docker container with
docker exec -it mysql1 bash
and runapt-get update
- Then run
apt-get install vim
apt-get install locales
- Run
dpkg-reconfigure locales
and select376
forru_RU.UTF-8
- Open ~/.bashrc and add
export LANG=ru_RU.utf8
export LANGUAGE=ru_RU.utf8
export LC_ALL=ru_RU.utf8
- 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.
Другие советы
Run the Docker container with a:
-e LANG=C.UTF-8
Or update your Dockerfile:
ENV LANG C.UTF-8