Skip to content

Connect to Percona XtraDB Cluster

In this tutorial, you will connect to the Percona XtraDB Cluster you deployed previously.

To connect to Percona XtraDB Cluster you will need the password for the root user. Passwords are stored in the Secrets object.

Here’s how to get it:

  1. List the Secrets objects

    $ kubectl get secrets -n <namespace>
    

    The Secrets object we target is named as <cluster_name>-secrets. The <cluster_name> value is the name of your Percona XtraDB Cluster. The default variant for the Secrets object is:

    cluster1-secrets

    cluster1-pxc-db-secrets

  2. Retrieve the password for the root user. Replace the secret-name and namespace with your values in the following commands:

$ kubectl get secret <secret-name> -n <namespace> --template='{{.data.root | base64decode}}{{"\n"}}'
  1. Run a container with mysql tool and connect its console output to your terminal. The following command does this, naming the new Pod percona-client:

    $ kubectl run -n <namespace> -i --rm --tty percona-client --image=percona:8.0 --restart=Never -- bash -il
    
    Executing it may require some time to deploy the correspondent Pod.

  2. Connect to Percona XtraDB Cluster. To do this, run mysql tool in the percona-client command shell using your cluster name and the password obtained from the secret. The command will look different depending on whether your cluster provides load balancing with HAProxy (the default choice) or ProxySQL. If your password contains special characters, they may be interpreted by the shell, and you may get “Permission denied” messages,so put the password in single quotes (single quotes also avoid variable expansion in scripts):

    $ mysql -h <cluster_name>-haproxy -uroot -p'<root_password>'
    
    $ mysql -h <cluster_name>-proxysql -uroot -p'<root_password>'
    

Congratulations! You have connected to Percona XtraDB Cluster.

Next steps

Insert sample data

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services. Join K8S Squad to benefit from early access to features and “ask me anything” sessions with the Experts.


Last update: 2024-11-26