mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 13 - Permission denied)

9/6/2020

docker-mysql-configmap.yml

apiVersion: v1
kind: ConfigMap
metadata:
    name: mysql-initdb-config 
data: 
    initdb.sql:
        use mydb;
        create table product(
        id int AUTO_INCREMENT PRIMARY KEY,
        name varchar(20),
        description varchar(100),
        price decimal(8,3) 
        );
            
        create table coupon(
        id int AUTO_INCREMENT PRIMARY KEY,
        code varchar(20) UNIQUE,
        discount decimal(8,3),
        exp_date varchar(100) 
        ); ```

db-mysql-service.yml

```apiVersion: v1
kind: Service
metadata:
    name: docker-mysql
    labels:
        app: docker-mysql
spec:
    selector:
        app: docker-mysql
    
    ports:
        - port: 3306
          targetPort: 3306     
          nodePort: 30287  
    type: NodePort 

        
   ``` >


db-sql-deplymonent.yml

```apiVersion: apps/v1
kind: Deployment
metadata: 
    name: docker-mysql
    labels:
        app: docker-mysql
spec:
    replicas: 1  
    selector:
        matchLabels:
            app: docker-mysql      
    template:
        metadata:
            labels: 
                app: docker-mysql
        spec:
          volumes: 
            - name: mysql-initdb-vol
              configMap:
                name: mysql-initdb-config 
          containers: 
                 - name: docker-mysql
                   image: mysql
                   volumeMounts:
                    - name:  mysql-initdb-vol
                      mountPath: /docker-entrypont-initdb.d
                   
                   
                   env:
                     - name: MYSQL_DATABASE 
                       value: mydb 
                     
                        
                     - name: MYSQL_ROOT_PASSWORD
                       value: norton09   
                     - name: MYSQL_ROOT_HOST
                       value: '%'   
                   

when i checking logs of pod i am getting errors.

2020-09-06 01:10:15+00:00 Note: Entrypoint script for MySQL Server 8.0.21-1debian10 started. 2020-09-06 01:10:15+00:00 ERROR: mysqld failed while attempting to check config command was: mysqld --verbose --help mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 13 - Permission denied) mysqld: ERROR Fatal error in defaults handling. Program aborted!

-- P S
docker
java
kubernetes
mysql

1 Answer

9/7/2020

You didn't mention what environment, kubernetes or mysql version are you using but there a few things which might help with this issue.

  1. Change access to this file/directory You also didnt mention if you want to check how it works or it will be used in production. If this solution would fit your needs you could change permissions to the file using chown command.

Additional information can be found in this thread or this.

  1. Disabling apparmor

As mentioned in this Github thread you can disable apparmor for mysql or use command form this comment. You can also check this thread for more information.

  1. Use privilaged option

It was cover by this SO question

You could also check this similar thread if you are using docker-compose.

Please let me know if any of those options worked for you or you still have issue.

-- PjoterS
Source: StackOverflow