当前位置:网站首页>K8s, docker compose install MySQL 8.0.18

K8s, docker compose install MySQL 8.0.18

2022-06-25 12:21:00 lihongbao80

One 、k8s install mysql 8.0.18

1、 Installation services

vim mysql-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
    name: mysql-deploy
    labels:
      name: mysql-deploy-label
    namespace: paas-db
spec:
    replicas: 1
    selector:
      matchLabels:
        name: mysql-pod
    template:
      metadata:
        labels: 
          name: mysql-pod
      spec:
        nodeSelector: 
          mysql: "true"
        terminationGracePeriodSeconds: 30  #k8s correct 、 Gracefully close the app , Waiting time 30 second 
        containers:
        - name: mysql-container
          image: mysql:8.0.18
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 3306
          env:
          - name: MYSQL_ROOT_PASSWORD
            value: "123456"
          - name: TIME_ZONE
            value: Asia/Shanghai
          volumeMounts:
          - name: mysql-volume
            mountPath: /var/lib/mysql
          #- name: mysql-conf
          # mountPath: /etc/mysql/conf.d
          - name: date-config
            mountPath: /etc/localtime
        volumes:
        - name: mysql-volume
          hostPath:
            path: /home/k8s-1.19.2/paas-db/mysql/volume
        #- name: mysql-conf
        # hostPath:
        # path: /home/k8s-1.19.2/paas-db/mysql/config/conf.d
        - name: date-config
          hostPath:
            path: /etc/localtime

vim mysql-service.yaml

#Service
apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  labels: 
    name: mysql-service-label
  namespace: paas-db
spec:
  type: NodePort
  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306
    name: http
    nodePort: 30306
  selector:
    name: mysql-pod

2、 Copy the configuration file from the container on the server where the data is landed

[[email protected] config]# docker cp c35f42eb5c0b:/etc/mysql/conf.d .
[[email protected] config]# ll
 Total usage  0
drwxrwxr-x 2 root root 41 12 month  29 2019 conf.d

3、 Get rid of deployment The profile comment for references an external profile

4、mysql8 In previous versions, the encryption rule was mysql_native_password, And in the mysql8 after , The encryption rule is caching_sha2_password, There are two ways to solve the problem , One is upgrading navicat drive , One is the mysql The encryption rule of user login password is restored to mysql_native_password

The phenomenon :
 Insert picture description here
Processing mode :
1、 install mysql Client access mysql
mysql -h 192.168.180.37 -P 30306 -uroot -p123456
Or enter mysql Containers , Log in to the container mysql

[[email protected] config]# docker exec -it c35f42eb5c0b bash
[email protected]-deploy-69978db9c8-jz6fc:/# mysql -h 127.0.0.1 -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

2、 Yes mysql Set the following .

MySQL [(none)]>  alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]>

Two 、docker-compose install mysql 8.0.18

version: '3'
services:
  db:
    # structure mysql Mirror image 
    image: mysql:8.0.18
    container_name: mysql #  Container name 
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root #root Administrator user password 
    ports:
    - '3306:3306'  #host The physical direct mapping port is 6606
    volumes:
    #mysql Mount the database to host Physical machine directory 
    - "./mysql_data:/var/lib/mysql"
    # The configuration directory of the container is mounted to host Physical machine directory 
    - "./conf:/etc/mysql/conf.d"
原网站

版权声明
本文为[lihongbao80]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200534500877.html