EDIT: 다음은 내 원래 질문에 대한 설명이지만 아직 문제를 해결하지 않은 한 로컬 컴퓨터의 구성 파일 mysql대신 생성된 POD 내부의 설정을 변경해야 한다고 생각했습니다. mysql하지만 POD 내부에서 변경을 시도하면 오류가 mysql발생합니다 command not found!

EDIT: 다음은 내 원래 질문에 대한 설명이지만 아직 문제를 해결하지 않은 한 로컬 컴퓨터의 구성 파일 mysql대신 생성된 POD 내부의 설정을 변경해야 한다고 생각했습니다. mysql하지만 POD 내부에서 변경을 시도하면 오류가 mysql발생합니다 command not found!

EDIT: 다음은 내 원래 질문에 대한 설명이지만 아직 문제를 해결하지 않은 한 로컬 컴퓨터의 구성 파일 mysql대신 생성된 POD 내부의 설정을 변경해야 한다고 생각했습니다. mysql하지만 POD 내부에서 변경을 시도하면 오류가 mysql발생합니다 command not found!

다음과 같이 클러스터 에서 실행 중인 mysql로컬에 이미지를 배포하려고 했습니다 .KubernetesKind

나는 다음과 같이 시도 kubectl create secret generic mysql-secret --from-literal MYSQL_KEY=11111하고 만들었습니다 .mysql-server

mysql-secret Opaque 1 3d21h

이것은 mysql-pv.yaml파일입니다:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

했고 kubectl apply -f mysql-pv.yaml성공적으로 생성되었습니다.

This is `mysql-depl.yaml` file:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secret
              key: MYSQL_KEY
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None

했고 kubectl apply -f mysql-depl.yaml성공적으로 생성되었습니다.

그러나 then 명령을 mysql사용하여 관련 포드 내부에서 실행하고 싶을 때 비밀번호를 묻고 비밀번호( )를 입력하면 다음과 같은 결과를 얻습니다.kubectl exec -it <mysql-pod-name> shmysql -p11111

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

내용은 다음 과 같습니다 /etc/mysql/my.cnf.

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

그 안에는 /etc/mysql/conf.d/두 개의 파일이 있습니다. mysql.cnf다음과 같이 :

[mysql]
socket  = /var/run/mysqld/mysqld.sock
[client]
socket  = /var/run/mysqld/mysqld.sock

그리고 mysqldump.cnf다음과 같습니다:

[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

또한 /etc/mysql/mysql.conf.d/디렉토리 내부에는 다음과 같은 두 개의 파일이 있습니다 mysql.cnf.


#
# The MySQL database client configuration file
#
# Ref to https://dev.mysql.com/doc/refman/en/mysql-command-options.html

[mysql]
socket  = /var/run/mysqld/mysqld.sock
[client]
socket  = /var/run/mysqld/mysqld.sock

그리고 mysqld.cnf:


#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket  = /var/run/mysqld/mysqld.sock
port        = 3306
datadir = /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir        = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size     = 16M
# max_allowed_packet    = 64M
# thread_stack      = 256K

# thread_cache_size       = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

# max_connections        = 151

# table_open_cache       = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file        = /var/log/mysql/query.log
# general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log        = 1
# slow_query_log_file   = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
# server-id     = 1
# log_bin           = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds    = 2592000
max_binlog_size   = 100M
# binlog_do_db      = include_database_name
# binlog_ignore_db  = include_database_name

또한 다음 파일이 포함되어 있습니다 /var/run/mysqld/.

mysqld.pid mysqld.sock mysqld.sock.lock mysqlx.sock mysqlx.sock.lock

답변1

mysql 컨테이너의 비밀번호 환경 변수를 잊어버린 것 같습니다. 이 단계를 다시 한번 확인해 주세요.

답변2

이 오류는 물리적 저장소의 소켓 파일(mysql.sock)과 컨테이너의 /var/run/mysqld/mysqld.sock 사이의 심볼릭 링크가 끊어진 경우 발생할 수 있습니다.

물리적 스토리지는 /var/lib/mysql에 마운트되므로 컨테이너의 /var/lib/mysql/mysql.sock에서 mysql.sock 파일을 찾을 수 있습니다.

그렇다면:

  1. bash 프롬프트를 얻기 위해 mysql 컨테이너에 실행

  2. 'ln -s /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock'을 실행하십시오.

  3. 그런 다음 mysql -u -p ...etc를 실행하여 로그인을 시도하십시오.

mysql 워크벤치가 여전히 만족스럽지 않다면 '호스트 플러시'를 실행해야 할 수도 있습니다.

관련 정보