docker pull mysql:8.0.21
mkdir -p /res/data/mysql/data /res/data/mysql/log /res/data/mysql/conf
docker run -d -p 3306:3306 --privileged=true \
-v /res/data/mysql/log:/var/log/mysql \
-v /res/data/mysql/data:/var/lib/mysql \
-v /res/data/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=root \
--name mysql \
mysql:8.0.21
docker exec -it 容器id /bin/bash
mysql -uroot -p
show variables like 'character%';
vim /res/data/mysql/conf/my.cnf
配置文件内容:
[client]
default_character_set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8
修改完配置后重启mysql容器实例
再次进入容器登录mysql并查看字符编码
再次进入容器登录mysql并查看字符编码
至此,docker安装MySQL完成!!