Cannot input Chinese in Docker-MySQL container

dockerhub pulls the MySQL image, starts and enters the container, and finds that Chinese cannot be entered in the MySQL command line, and Chinese cannot be entered when exiting the container terminal.

container terminal view locale

# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"

The POSIX character set is used by default in the container system, and the POSIX character set does not support Chinese.

View container system support character set

# locale -a
C
C.UTF-8
POSIX

C.UTF-8 supports Chinese, and the problem can be solved by changing the language environment LANG in the system to "C.UTF-8" format.

1. Temporary modification

Method 1. Enter the Mysql container command

docker exec -it 容器id env LANG=C.UTF-8 /bin/sh

Method 2. Terminal execution in the Mysql container

export LANG=C.UTF-8 # 临时生效

2. Persistent modification - Dockerfile

For permanent modification, it needs to be set in the Dockerfile when creating the image.

Add a line of ENV LANG C.UTF-8 to the Dockerfile to recreate the Mysql image

FROM mysql:8.0

ENV LANG C.UTF-8

3. Persistent modification - docker-compose.yml

Add the following configuration to docker-compose.yml:

environment:
    TZ: "Asia/Shanghai"
    LANG: en_US.UTF-8
    volumes:
    - /etc/localtime:/etc/localtime:ro

Guess you like

Origin blog.csdn.net/wangshiqi666/article/details/130498331