如何在 kubernetes 中禁用 mysql 严格模式?
How to disable mysql strict mode in kubernetes?
我想在默认禁用严格模式的 Kubernetes 中创建一个 MySQL 容器。我知道如何在 docker 中禁用严格模式。我尝试在 Kubernetes 中使用相同的方式,但它显示错误日志。
docker
docker container run -t -d --name hello-wordl mysql --sql-mode=""
kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-db
labels:
app: db
spec:
selector:
matchLabels:
app: db
template:
metadata:
name: my-db
labels:
app: db
spec:
containers:
- name: my-db
image: mariadb
imagePullPolicy: Always
args: ["--sql-mode=\"\""]
错误:
2021-10-29 08:20:57+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.2.40+maria~bionic started.
2021-10-29 08:20:57+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
command was: mysqld --sql-mode="" --verbose --help --log-bin-index=/tmp/tmp.i8yL5kgKoq
2021-10-29 8:20:57 140254859638464 [ERROR] mysqld: Error while setting value '""' to 'sql_mode'
看来你必须为此使用 configmap
。
Configmap 清单:
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
labels:
app: mysql
data:
my.cnf: |-
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
max_connections = 2000
secure_file_priv=/var/lib/mysql
sql_mode=STRICT_TRANS_TABLES
部署清单:在卷部分
volumeMounts:
- name: data
mountPath: /var/lib/mysql
- name: config
mountPath: /etc/mysql/conf.d/my.cnf
subPath: my.cnf
volumes:
- name: config
configMap:
name: mysql-config
这将替换 MySQL 容器中的默认 my.conf
,如果您需要设置更多变量,最好将它们包含在 configmap
中
For more detailed answer
根据您遇到的错误,它正在读取双引号作为 sql_mode 的值。您应该省略转义双引号。
args: ["--sql-mode="]
我想在默认禁用严格模式的 Kubernetes 中创建一个 MySQL 容器。我知道如何在 docker 中禁用严格模式。我尝试在 Kubernetes 中使用相同的方式,但它显示错误日志。
docker
docker container run -t -d --name hello-wordl mysql --sql-mode=""
kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-db
labels:
app: db
spec:
selector:
matchLabels:
app: db
template:
metadata:
name: my-db
labels:
app: db
spec:
containers:
- name: my-db
image: mariadb
imagePullPolicy: Always
args: ["--sql-mode=\"\""]
错误:
2021-10-29 08:20:57+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.2.40+maria~bionic started. 2021-10-29 08:20:57+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config command was: mysqld --sql-mode="" --verbose --help --log-bin-index=/tmp/tmp.i8yL5kgKoq 2021-10-29 8:20:57 140254859638464 [ERROR] mysqld: Error while setting value '""' to 'sql_mode'
看来你必须为此使用 configmap
。
Configmap 清单:
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
labels:
app: mysql
data:
my.cnf: |-
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
max_connections = 2000
secure_file_priv=/var/lib/mysql
sql_mode=STRICT_TRANS_TABLES
部署清单:在卷部分
volumeMounts:
- name: data
mountPath: /var/lib/mysql
- name: config
mountPath: /etc/mysql/conf.d/my.cnf
subPath: my.cnf
volumes:
- name: config
configMap:
name: mysql-config
这将替换 MySQL 容器中的默认 my.conf
,如果您需要设置更多变量,最好将它们包含在 configmap
中
For more detailed answer
根据您遇到的错误,它正在读取双引号作为 sql_mode 的值。您应该省略转义双引号。
args: ["--sql-mode="]