一、查看client的语言格式
将语言格式均设置为C.UTF-8,可以通过在Dockerfile里添加ENV命令来设置语言格式。
root@3430f38caf85:/# locale
LANG=C.UTF-8
LANGUAGE=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=C.UTF-8
二、查看mysql容器编码格式
可以看到很多项目的语言格式不是utf8
image.png
二、设置mysql容器全局编码为UTF-8,修改my.cnf文件
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
之后再查看语言格式,已经变为utf8。
mysql> show variables like '%char%';
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
之后重启mysql容器.
注意:读取修改my.cnf文件之前建的table依然会有乱码,修改后新建table才不会有乱码!!!!
网友评论