Docker安装mysql
默认安装最新版本的mysql (latest)
安装指定版本的mysql
1
| docker pull mysql:8.0.20
|
安装mysql容器
1 2 3 4 5 6 7
| 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:8.0.20
|
创建mysql配置文件
在/mydata/mysql/conf
目录下创建文件my.cnf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| [client] default-character-set=utf8mb4
[mysql] default-character-set=utf8mb4
[mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve secure_file_priv=/var/lib/mysql skip-grant-tables #可以跳过登录mysql
|
重启容器
进入mysql容器(linux系统)
1
| docker exec -it mysql /bin/bash
|
查看是否成功修改
设置mysql随着docker自启
1 2 3 4
| docker update mysql --restart=always
docker update redis --restart=always
|