zoukankan      html  css  js  c++  java
  • k8s 运行 mysql 报错 initialize specified but the data directory has files in it

    最近在 k8s 上面运行 mysql 报错

    $ kubectl -n devops logs mysql-679745f64f-4cdzc 
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
    2021-12-10 01:18:26+00:00 [Note] [Entrypoint]: Initializing database files
    2021-12-10T01:18:26.354668Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-12-10T01:18:26.355814Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
    2021-12-10T01:18:26.355851Z 0 [ERROR] Aborting
    

    提示数据目录非空,什么鬼,好吧,我们先运行一个 initContainers 看看目录里面到底有啥

          initContainers:
          - name: init-data-path
            image: hub.leffss.com/library/busybox:v1.28.4
            imagePullPolicy: IfNotPresent
            command: ["sh", "-c", "ls -l /var/lib/mysql"]
            securityContext:
              privileged: true
            volumeMounts:
            - name: mysql-pvc
              mountPath: /var/lib/mysql
    
    # 查看 initContainers 的日志
    kubectl -n devops logs mysql-679745f64f-4cdzc -c init-data-path
    total 16
    drwx------    2 root     root         16384 Dec 10 01:18 lost+found
    

    原来是 lost+found,这个目录啥东西,有啥用这里就不介绍了,自己百度,反正以我工作这么多年的经验来说,没啥用

    为啥会有这个目录呢?因为我们 pvc 使用的是 ceph 的 rbd,每次创建时都会格式化,就会产生这个,如果使用 cephfs 或者 nfs 的话,不会有这个目录

    好吧,既然没用,那就盘它:

          initContainers:
          - name: init-data-path
            image: hub.leffss.com/library/busybox:v1.28.4
            imagePullPolicy: IfNotPresent
            command: ["sh", "-c"]
            args:
            - |
              if [[ -d /var/lib/mysql/lost+found ]];then
                echo "rm -rf /var/lib/mysql/lost+found"
                rm -rf /var/lib/mysql/lost+found
              else
                echo "/var/lib/mysql/lost+found not exist"
              fi
            securityContext:
              privileged: true
            volumeMounts:
            - name: mysql-pvc
              mountPath: /var/lib/mysql
    

    删除,整个世界清净了!

    $ kubectl -n devops get pod
    NAME                     READY   STATUS    RESTARTS   AGE
    mysql-774868b794-8d258   1/1     Running   0          13m
    redis-7b4c48fd74-g99zg   1/1     Running   0          32m
    
  • 相关阅读:
    软键盘的监听
    获取视频播放时长
    安装hue及hadoop和hive整合
    Centos6.5使用yum安装mysql——快速上手必备(转载)
    Hadoop yarn任务调度策略介绍(转)
    CentOS下RPM方式安装MySQL5.6(转载)
    exists,in的区别-mysql
    CentOS命令登录MySQL时,报错ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)错误解决方法
    SpringMVC+Apache Shiro+JPA(hibernate)案例教学(四)基于Shiro验证用户权限,且给用户授权
    SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码
  • 原文地址:https://www.cnblogs.com/leffss/p/15670341.html
Copyright © 2011-2022 走看看