rh0*_*h0x 5 mysql innodb initialization kubernetes mysql-operator
我已经在 Kubernetes 中成功部署了InnoDB Clustervia mysql-operator,并且还设置了计划备份。我还可以通过 InnoDB 创建的相同备份来初始化数据库。
但是,我无法找到通过导入由简单脚本定义的简单逻辑备份来首次初始化数据库.sql的方法。
是否可以通过 mysql-operator 或 InnoDB kubernetes 清单来实现?可能的替代方案?
相关文档:
InnoDBCluster 清单:
apiVersion: mysql.oracle.com/v2
kind: InnoDBCluster
metadata:
name: mysql-cluster
namespace: cr-platform
spec:
secretName: mysql-root-user
instances: 2
tlsUseSelfSigned: true
router:
instances: 1
backupSchedules:
- name: daily-2300
enabled: true
schedule: "0 23 * * *"
backupProfileName: s3-backup
backupProfiles:
- name: s3-backup
dumpInstance:
dumpOptions:
chunking: false
storage:
s3:
bucketName: al-mysql
prefix: /backup
config: s3-secret
profile: default
endpoint: https://s3-endpoint
## Restore from InnoDB dump but not from .sql script
initDB:
dump:
dumpOptions:
dryRun: false
storage:
# backup
s3:
bucketName: al-mysql
prefix: /init
config: s3-secret
profile: default
endpoint: https://s3-endpoint
Run Code Online (Sandbox Code Playgroud)
我发现的方法是执行 mysql 客户端 pod,进行登录,然后导入 sql 脚本。
# 1. deploy mysql-client
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-init
data:
1-init.sql:
# YOUR SQL INIT SCRIPT HERE
---
apiVersion: v1
kind: Pod
metadata:
name: mysql-client
spec:
containers:
- name: mysql
image: mysql:8.0
ports:
- containerPort: 80
env:
- name: MYSQL_ALLOW_EMPTY_PASSWORD
value: "true"
volumeMounts:
- name: config-volume
mountPath: /init/
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: mysql-init
# 2. run the import:
# enter the shell for the client pod and run the following commands by substituting:
# <MYSQL-SERVER-HOST> with the service name exposing the mysql-cluster on kubernetes cluster and <USER>/<PASSWORD> credentials with the ones defined as kubernetes secret in the mysql-cluster namespace
mysql -h <MYSQL-SERVER-HOST> -u<USER> -p<PASSWORD> -e 'SHOW databases;'
mysql -h <MYSQL-SERVER-HOST> -u<USER> -p<PASSWORD> < init/1-init.sql
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
508 次 |
| 最近记录: |