Skip to content
logo
Percona Operator for MySQL
Changing MySQL Options
Initializing search
    percona/k8sps-docs
    percona/k8sps-docs
    • Welcome
      • Design and architecture
      • Install with Helm
      • Install on Minikube
      • System Requirements
      • Install on Google Kubernetes Engine (GKE)
      • Install on Amazon Elastic Kubernetes Service (AWS EKS)
      • Generic Kubernetes installation
      • Backup and restore
      • Application and system users
      • Anti-affinity and tolerations
      • Labels and annotations
      • Changing MySQL Options
        • Edit the deploy/cr.yaml file
        • Use a ConfigMap
        • Use a Secret Object
        • Auto-tuning MySQL options
      • Exposing the cluster
      • Transport Encryption (TLS/SSL)
      • Telemetry
      • Horizontal and vertical scaling
      • Monitor with Percona Monitoring and Management (PMM)
      • Add sidecar containers
      • Monitor Kubernetes
      • Custom Resource options
      • Percona certified images
      • Copyright and licensing information
      • Trademark policy
      • Release notes index
      • Percona Operator for MySQL 0.5.0 (2023-03-30)
      • Percona Operator for MySQL 0.4.0 (2023-01-30)
      • Percona Operator for MySQL 0.3.0 (2022-09-29)
      • Percona Operator for MySQL 0.2.0 (2022-06-30)
      • Percona Distribution for MySQL Operator based on Percona Server for MySQL 0.1.0 (2022-01-25)

    • Edit the deploy/cr.yaml file
    • Use a ConfigMap
    • Use a Secret Object
    • Auto-tuning MySQL options

    Changing MySQL Options¶

    You may require a configuration change for your application. MySQL allows the option to configure the database with a configuration file. You can pass options from the my.cnf configuration file to be included in the MySQL configuration in one of the following ways:

    • edit the deploy/cr.yaml file,

    • use a ConfigMap,

    • use a Secret object.

    Edit the deploy/cr.yaml file¶

    You can add options from the my.cnf configuration file by editing the configuration section of the deploy/cr.yaml. Here is an example:

    spec:
      secretsName: cluster1-secrets
      mysql:
        ...
          configuration: |
            max_connections=250
    

    See the Custom Resource options, MySQL section for more details.

    Use a ConfigMap¶

    You can use a configmap and the cluster restart to reset configuration options. A configmap allows Kubernetes to pass or update configuration data inside a containerized application.

    Use the kubectl command to create the configmap from external resources, for more information see Configure a Pod to use a ConfigMap.

    For example, let’s suppose that your application requires more connections. To increase your max_connections setting in MySQL, you define a my.cnf configuration file with the following setting:

    max_connections=250
    

    You can create a configmap from the my.cnf file with the kubectl create configmap command.

    You should use the combination of the cluster name with the -mysql suffix as the naming convention for the configmap. To find the cluster name, you can use the following command:

    $ kubectl get ps
    

    The syntax for kubectl create configmap command is:

    $ kubectl create configmap <cluster-name>-mysql <resource-type=resource-name>
    

    The following example defines cluster1-mysql as the configmap name and the my.cnf file as the data source:

    $ kubectl create configmap cluster1-mysql --from-file=my.cnf
    

    To view the created configmap, use the following command:

    $ kubectl describe configmaps cluster1-mysql
    

    Use a Secret Object¶

    The Operator can also store configuration options in Kubernetes Secrets. This can be useful if you need additional protection for some sensitive data.

    You should create a Secret object with a specific name, composed of your cluster name and the mysql suffix.

    Note

    To find the cluster name, you can use the following command:

    $ kubectl get ps
    

    Configuration options should be put inside a specific key inside of the data section. The name of this key is my.cnf for Percona Server for MySQL pods.

    Actual options should be encoded with Base64.

    For example, let’s define a my.cnf configuration file and put there a pair of MySQL options we used in the previous example:

    max_connections=250
    

    You can get a Base64 encoded string from your options via the command line as follows:

    $ cat my.cnf | base64 --wrap=0
    
    $ cat my.cnf | base64
    

    Note

    Similarly, you can read the list of options from a Base64 encoded string:

    $ echo "bWF4X2Nvbm5lY3Rpb25zPTI1MAo" | base64 --decode
    

    Finally, use a yaml file to create the Secret object. For example, you can create a deploy/mysql-secret.yaml file with the following contents:

    apiVersion: v1
    kind: Secret
    metadata:
      name: cluster1-mysql
    data:
      my.cnf: "bWF4X2Nvbm5lY3Rpb25zPTI1MAo"
    

    When ready, apply it with the following command:

    $ kubectl create -f deploy/mysql-secret.yaml
    

    Note

    Do not forget to restart Percona Server for MySQL pods to ensure the cluster has updated the configuration. You can do it with the following command:

    $ kubectl rollout restart statefulset cluster1-mysql
    

    Auto-tuning MySQL options¶

    Few configuration options for MySQL can be calculated and set by the Operator automatically based on the available Pod memory resource limits if constant values for these options are not specified by the user (either in cr.yaml or in ConfigMap).

    Options which can be set automatically are the following ones:

    • innodb_buffer_pool_size

    • max_connections

    If Percona Server for MySQL container resource limits are defined, then limits values are used to calculate these options. If Percona Server for MySQL container resource limits are not defined, auto-tuning is not done.

    Also, starting from the Operator 0.4.0, there is another way of auto-tuning. You can use "{{ containerMemoryLimit }}" as a value in spec.mysql.configuration as follows:

    mysql:
        configuration: |
        [mysqld]
        innodb_buffer_pool_size={{containerMemoryLimit * 3 / 4}}
        ...
    

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-08-31
    Percona LLC and/or its affiliates, © 2009 - 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better. Read more about Percona Cookie Policy.