首页 > 数据库 >(初学)记一次dockercompose安装mysql8 以及问题

(初学)记一次dockercompose安装mysql8 以及问题

时间:2022-11-15 11:25:34浏览次数:47  
标签:dockercompose service NO mysql8 etc ZERO 初学 mysql docker

docker-compose文件如下:

 1 version: '3'
 2 services:
 3   # mysql服务
 4   service-mysql:
 5     image: docker.io/mysql:8.0.27
 6     command: 
 7       --default-authentication-plugin=mysql_native_password
 8       --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
 9       --max_connections=2000
10     ports:
11       - '3306:3306'
12     environment:
13       - MYSQL_ROOT_PASSWORD=root
14       - MYSQL_USER: 'test'
15         - MYSQL_PASS: 'test'
16     privileged: true
17     volumes:
18       - /etc/localtime:/etc/localtime:ro
19       - /etc/timezone:/etc/timezone:ro
20       - ./conf/mysql.cnf:/etc/mysql/my.cnf
21       - ./data:/var/lib/mysql      
22     restart: always
23     container_name: service-mysql
24     networks:
25       - custom_network
26       
27   # mysql phpmyadmin服务
28   service-mysql-admin:
29     image: phpmyadmin/phpmyadmin    
30     ports:
31       - '3307:80'
32     environment:
33       - PMA_ARBITRARY=1
34       - PMA_HOST=service-mysql
35     volumes:
36       - /etc/localtime:/etc/localtime:ro
37     depends_on:
38       - service-mysql
39     restart: always
40     container_name: service-mysql-admin
41     networks:
42       - custom_network
43 
44 networks:
45   custom_network:
46     external:
47       name: service

my.cn映射如下:

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
skip-character-set-client-handshake
skip-name-resolve
secure-file-priv= NULL


sql_mode        =STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

max_connections = 2000

配置成功后,使用docker up -d安装,安装成功后,通过docker ps -a查看安装运行情况:

 

 

 

此时安装成功,正常连接mysql即可。

可能会遇到问题:

docker-compose文件中设置的密码无效、远程方式无效

  解决方案:

  在映射的my.cnf文件中,加入 :skip-grant-tables 跳过密码验证

  

 

 

   重启docker容器,通过:docker exec -it service-mysql bash(注:ocker exec -it 容器名称 bash) 进入容器,登录mysql,此时无需密码

 登录mysql后执行命令:

  alter user 'root'@'localhost' identified with mysql_native_password by 'youpassword';

  刷新权限:flush privileges;

 

设置远程可登录:

  GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

  刷新权限:flush privileges;

 

 

 全部执行完毕后,重启docker容器,再测试连接:

 

标签:dockercompose,service,NO,mysql8,etc,ZERO,初学,mysql,docker
From: https://www.cnblogs.com/wql-987426546/p/16891686.html

相关文章

  • Ubuntu20.04离线安装mysql8.0
    参考网址#1.官网下载对应的文件并解压tar-xfmysql-server_8.0.31-1ubuntu20.04_amd64.deb-bundle.tar#2.下载所需的依赖wgethttp://archive.ubuntu.com/ubuntu/pool......
  • mysql8创建组合索引
    https://wenku.baidu.com/view/63898d1d0a12a21614791711cc7931b764ce7b40.html?wkts=1668415162513&bdQuery=mysql8+%E7%BB%84%E5%90%88%E7%B4%A2%E5%BC%95https://www.c......
  • 4.docker mgr(mysql8.0.27)多机多节点搭建
    1.环境准备(已关闭防火墙和selinux)1.1服务器列表 1.2修改3台服务器的hosts文件,否则会报错解析不到node1,原因参考(https://www.cnblogs.com/zhangdapangzo/......
  • Mysql8.0本地Datagrip失败--时区
    新版的Mysql中的时区默认设置与本地时区之间是不同的,因此会报错。由此,解决方法即为修改时区设置即可 ?serverTimezone=UTC ......
  • linux下安装MySQL8.0
    linux下安装MySQL8.0本次安装演示版本为8.0.281、准备安装目录及其安装包cd/usr/local/mkdirmysqlcdmysql#使用wget下载mysql安装包(如果下载慢,可自行提前准备安......
  • 【MySQL8】中文分词支持全文索引
    参考:https://blog.csdn.net/qq_54169998/article/details/122471199第一步:配置文件my.ini(Windows10默认路径:C:\ProgramData\MySQL\MySQLServer8.0)中增加如下配置......
  • 新手初学c语言
    #include<stdio.h>intmain(){   printf("您好这是我写的第一个代码");   return0; }第二个代码#include<stdio.h>intmain(){inta=0;intb=0;intc=0;scanf_......
  • Mysql8创建用户以及赋权操作
    1.使用root进入mysqlmysql>mysql-uroot-p 2.使用命令创建用户tmc设置密码123456mysql>createuser'tmc'@'%'identifiedby'123456';QueryOK,0rows......
  • CentOS7 安装mysql8
    1、下载并解压mysql安装包https://downloads.mysql.com/archives/community/  放到服务器后解压-C放到指定文件夹tar-xvfmysql-8.0.30-linux-glibc2.12-x86......
  • docker安装mysql8
    1、问题描述docker安装mysql8,记录下;2、问题说明2.1查看下目前服务器镜像dockerimages2.1拉取最新mysql,5.8版本dockerpullmysql2.3run,构建容器命令:docker......