docker安装mysql5.7

# 拉取镜像
docker pull mysql:5.7
# 创建配置目录
mkdir -p ~/mydata/mysql/conf
# 创建配置文件
cat > ~/mydata/mysql/conf/my.cnf << EOF
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
init_connect='SET collation_connection=utf_unicode_ci'
init_connect='SET NAMES uft8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
# 解决客户端连接慢,跳过域名解析
skip-name-resolve
EOF
# 启动容器
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
# 设置自动启动
docker update mysql --restart=always
# 进入客户端
docker exec -it mysql mysql -uroot -proot
# 授权远程访问
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;

posted @ 2021-01-29 11:56  java拌饭  阅读(43)  评论(0编辑  收藏  举报