拉取镜像
启动
1
| docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
|
修改配置文件
因为使用了容器挂载,所以只需要在其映射文件中修改 主要修改字符集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| # 进入映射文件 cd /mydata/mysql/conf #修改文件 vi my.cnf # 编写配置 [client] default-character-set=utf-8
[mysql] default-character-set=utf-8
[mysqld] init_connect='SET collation_connection=utf8_unicode_ci' init_connect='SER NAMES uft8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
|
重启mysql
compose
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| version: '3' services: mysql8: image: mysql:8.0 container_name: mysql8 restart: always environment: MYSQL_ROOT_PASSWORD: 123456 TZ: Asia/Shanghai command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-authentication-plugin=mysql_native_password --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M; ports: - 3306:3306 volumes: # 映射SQL文件 - /mydata/mysql/log:/var/log/mysql - /mydata/mysql/data:/var/lib/mysql - /mydata/mysql/conf:/etc/mysql # ro只读模式 - /etc/localtime:/etc/localtime:ro
|
作者声明