赞
踩
本文基于MySQL5.7.42进行说明
常规命令(不适用),提示no matching manifest for linux/arm64/v8 in the manifest list entries
docker pull mysql:5.7.42
到DockerHub查看MySQL5.7.42的镜像,可以看到确实没有linux/arm64/v8版本的镜像
因此我们要另辟蹊径,加入指定架构的参数进行拉取
docker pull --platform linux/amd64 mysql:5.7.42
--platform linux/amd64:Docker拉取镜像时指定拉取所选架构的版本
在应用端的镜像界面和启动镜像的时候,Docker会检测到该镜像支持的架构与电脑的CPU架构不一致,忽略即可(M1/M2芯片也是支持linux/amd64版本的)
- # 启动镜像并进入容器
- docker run -it mysql:5.7.42 /bin/bash
- # 查看MySQL版本
- mysql --version
- # 查找 Docker 内,MySQL 配置文件 my.cnf 的位置
- mysql --help | grep my.cnf
查看MySQL配置文件my.cnf内容(如下)
- bash-4.2# cat my.cnf
- # For advice on how to change settings please see
- # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
-
- [mysqld]
- #
- # Remove leading # and set to the amount of RAM for the most important data
- # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
- # innodb_buffer_pool_size = 128M
- #
- # Remove leading # to turn on a very important data integrity option: logging
- # changes to the binary log between backups.
- # log_bin
- #
- # Remove leading # to set options mainly useful for reporting servers.
- # The server defaults are faster for transactions and fast SELECTs.
- # Adjust sizes as needed, experiment to find the optimal values.
- # join_buffer_size = 128M
- # sort_buffer_size = 2M
- # read_rnd_buffer_size = 2M
- skip-host-cache
- skip-name-resolve
- datadir=/var/lib/mysql
- socket=/var/run/mysqld/mysqld.sock
- secure-file-priv=/var/lib/mysql-files
- user=mysql
-
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
-
- #log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [client]
- socket=/var/run/mysqld/mysqld.sock
-
- !includedir /etc/mysql/conf.d/
- !includedir /etc/mysql/mysql.conf.d/
默认配置并未指定字符集,此时默认字符集为latin1,可能会导致一些中文字符乱码,因此我们可以修改配置文件,添加默认字符集(见下节)
1. 宿主机创建数据存储目录(可以是其他位置,/Users/leo笔者Mac上的用户目录,等价于~目录,读者自行调整目录)
- mkdir /Users/leo/docker/mysql
- mkdir /Users/leo/docker/mysql/conf
- mkdir /Users/leo/docker/mysql/data
- mkdir /Users/leo/docker/mysql/logs
- mkdir /Users/leo/docker/mysql/mysql-files
2. 新建my.cnf配置文件并放到/Users/leo/docker/mysql/conf目录下
my.cnf配置如下:
- [client]
-
- default_character_set=utf8
-
- [mysql]
-
- default_character_set=utf8
-
- [mysqld]
-
- character_set_server=utf8
- docker run --restart=always -p 3306:3306 --name mysql \
- -e MYSQL_ROOT_PASSWORD="123456" \
- -v /Users/leo/docker/mysql/conf:/etc/mysql/conf.d \
- -v /Users/leo/docker/mysql/logs:/var/log/mysql \
- -v /Users/leo/docker/mysql/data:/var/lib/mysql \
- -v /Users/leo/docker/mysql/mysql-files:/var/lib/mysql-files \
- -d mysql:5.7.42
参数说明:
root
用户的密码为 123456
)- # 进入名为mysql的容器
- docker exec -ti mysql bash
- # 命令行连接MySQL
- mysql -uroot -p'jY%kng8cc&'
- # 查看字符集
- show variables like 'char%';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。