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;
标签:opt,slow,log,mysql8,0.7,mysql,docker 来源: https://blog.csdn.net/weixin_45501950/article/details/122114515