Skip to content

Rate this page
Thanks for your feedback
Thank you! The feedback has been submitted.

Get free database assistance or contact our experts for personalized support.

Connect to Percona Server for MySQL

In this tutorial, you will connect to the Percona Server for MySQL you deployed previously.

The Operator creates a dedicated Secret named <cluster_name>-psuser-root that contains all connection details for the root user: hostname, port, username, password, and ready-to-use URIs. The Operator keeps this Secret up to date on every reconciliation.

Here’s how to connect:

  1. Export the namespace, cluster name and the Secret name as environment variables:

    export NAMESPACE=my-namespace
    export CLUSTER_NAME=ps-cluster1
    export SECRET_NAME=${CLUSTER_NAME}-psuser-root
    

    Replace ps-cluster1 with the name of your cluster if you changed it during installation.

  2. Verify that the connection Secret exists:

    kubectl get secret $SECRET_NAME -n $NAMESPACE
    

    Look for the Secret named <cluster_name>-psuser-root. The default name differs on how you installed the Operator:

    ps-cluster1-psuser-root

    my-db-ps-db-psuser-root

  3. Retrieve the user credentials from the Secret:

    bash kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" \ -o jsonpath='{.data.user}' | base64 --decode && echo kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" \ -o jsonpath='{.data.password}' | base64 --decode && echo

  4. Run a container with the mysql client 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/percona-server:8.4 --restart=Never -- bash -il
    

    Executing it may require some time to deploy the corresponding Pod.

  5. Connect to Percona Server for MySQL. To do this, run mysql tool in the percona-client command shell using your cluster name and the password obtained from the secret instead of the <root_password> placeholder. The command will look different depending on whether your cluster uses load balancing with HAProxy (the default behavior) or uses MySQL Router (can be used with Group Replication clusters only):

    mysql -h <cluster_name>-haproxy -uroot -p'<root_password>'
    
    mysql -h <cluster_name>-router -uroot -p'<root_password>'
    

Congratulations! You have connected to Percona Server for MySQL.

Next steps

Insert sample data


Last update: July 3, 2026
Created: March 25, 2024