0.7 docker 安装mysql8

2021/12/24 2:08:29

本文主要是介绍0.7 docker 安装mysql8,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  • 搜索mysql
docker search mysql
  • 拉取 mysql
docker pull mysql:8.0
  • 查看 mysql 镜像
  • 创建 目录
mkdir -p /opt/docker/mysql8
  • 创建mysql配置文件/opt/docker/mysql8/my.cnf
[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000
bind-address=0.0.0.0
default-time-zone = '+08:00'
skip-name-resolve
lower_case_table_names=1
slow_query_log =1
slow_query_log_file=/opt/docker/mysql8/slow/localhost-slow.log
long_query_time = 10
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8
  • 安装
docker run --restart=always --privileged=true -p 3306:3306 --name mysql8 \
-v /opt/docker/mysql8/my.cnf:/etc/mysql/my.cnf \
-v /opt/docker/mysql8/conf.d:/etc/mysql/conf.d \
-v /opt/docker/mysql8/logs:/var/log/mysql \
-v /opt/docker/mysql8/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql

  • 查看日志
docker logs -f mysql8
  • 设置时区,否则和宿主机相差8个小时,以及远程连接出现中断的情况
docker cp /usr/share/zoneinfo/Asia/Shanghai mysql8:/etc/localtime
  • 进入mysql8 容器
docker exec -it mysql8 bash
  • 登录MYSQL
mysql -uroot -p123456
  • 查看用户表
show databases;
use mysql;
select host,user from user;
  • 授权远程访问
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;


这篇关于0.7 docker 安装mysql8的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程