debugsqldockerMinor
Unable to use cyrillic characters in mysql docker console
Viewed 0 times
dockerconsoleunablecyrillicmysqlcharactersuse
Problem
I'm running a MySQL docker container (latest - 8.0) with the custom configuration file containing:
Executing inside MySQL console:
produces this:
Executing inside MySQL console:
produces this:
BUT when I go the MySQL console with:
I can't use cyrillic (russian) characters. When I switch to Russian locale and try to type anything, the console just ignores keypresses, nothing
======================================
[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
Solution
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:
export LANG=ru_RU.utf8
export LANGUAGE=ru_RU.utf8
export LC_ALL=ru_RU.utf8
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.
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 bashand runapt-get update
- Then run
apt-get install vimapt-get install locales
- Run
dpkg-reconfigure localesand select376forru_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.
Context
StackExchange Database Administrators Q#225942, answer score: 7
Revisions (0)
No revisions yet.