docker修改mysql容器配置文件解决中文乱码的问题
解决方法:
-
1.进入容器
-
2.进入etc/mysql,查看my.cnf文件,说明要修改的文件在/etc/mysql/conf.d/和/etc/mysql/mysql.conf.d/下面
-
3.进入/etc/mysql/conf.d/,修改docker.cnf
[mysqld] skip-host-cache skip-name-resolve character_set_server=UTF8MB4
-
4.修改mysql.cnf
[mysql]
default-character-set=UTF8MB4
[mysql.server]
default-character-set=UTF8MB4
[mysql_safe]
default-character-set=UTF8MB4
[client]
default-character-set=UTF8MB4
- 5.进入/etc/mysql/mysql.conf.d/,修改mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character_set_server=UTF8MB4
init_connect='SET NAMES utf8'
[mysql]
default-character-set = UTF8MB4
[mysql.server]
default-character-set = UTF8MB4
[mysqld_safe]
default-character-set = UTF8MB4
[client]
default-character-set = UTF8MB4
- 6.重启容器
- 7.进入mysql命令行输入:show variables like ‘char%’;
修改成功