my.cnf in kubernetes configmap is not recognized by mysql pod.
This is mysql.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: *****
name: *****
spec:
serviceName: mysql-service
replicas: 1
selector:
matchLabels:
app: *****
template:
metadata:
labels:
app: *****
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: eks.amazonaws.com/nodegroup
operator: In
values:
- db-node
containers:
- name: mysql
image: mysql:5.7
args:
- "--ignore-db-dir=lost+found"
env:
- name: MYSQL_ROOT_PASSWORD
value: password
- name: MYSQL_USER
value: mysql
- name: MYSQL_DATABASE
value: ****
ports:
- containerPort: 3306
protocol: TCP
volumeMounts:
- name: *****
mountPath: /var/lib/mysql
- name: mysql-configmap
mountPath: /etc/mysql/conf.d/mysql.cnf
subPath: mysql.cnf
volumes:
- name: mysql-configmap
configMap:
name: mysql-configmap
configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-configmap
namespace: ****
data:
mysql.cnf: |
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
MySQL Container in my.cnf
root@********:/etc/mysql/conf.d# cat mysql.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
The file is located in the folder, but the settings I want are not applied.
mysql> show variables like 'char%'; +--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
Thank you for reading.
I think it's because my.cnf is root authority, but it's not visible in other use cases.
From the official documentation of the docker image found here this could have several reasons.
Check the default mysql configuration under
/etc/mysql/my.cnfif there is anincludedirstatement which includes your/etc/mysql/conf.ddirectory with your custom configuration.It is also possible to add encoding options as arguments, meaning that if you cannot fix it via the configmap option you are using right now, you could add extra arguments to your mysql image.
Your statefulset yaml would then look like that:
The documentation uses
--character-set-server=utf8mb4instead ofdefault-character-set=utf8so you might need to try both options to find out which one is the corret one.